Skip to content

Commit ecb5af2

Browse files
committed
Add Typescript definition
1 parent 6097484 commit ecb5af2

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 2.0
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { ArrayLike } from '@stdlib/types/array';
24+
25+
/**
26+
* Computes the minimum and maximum linear indices in an underlying data buffer which are accessible to an array view.
27+
*
28+
* @param shape - array shape
29+
* @param strides - stride array
30+
* @param offset - index offset
31+
* @returns linear indices
32+
*
33+
* @example
34+
* var shape = [ 10, 10 ];
35+
* var strides = [ 10, 1 ];
36+
* var offset = 10;
37+
*
38+
* var idx = minmaxViewBufferIndex( shape, strides, offset );
39+
* // returns [ 10, 109 ]
40+
*
41+
* @example
42+
* var shape = [ 10, 10 ];
43+
* var strides = [ -10, -1 ];
44+
* var offset = 99;
45+
*
46+
* var idx = minmaxViewBufferIndex( shape, strides, offset );
47+
* // returns [ 0, 99 ]
48+
*
49+
* @example
50+
* var shape = [ 10, 10 ];
51+
* var strides = [ 1, 10 ];
52+
* var offset = 10;
53+
*
54+
* var idx = minmaxViewBufferIndex( shape, strides, offset );
55+
* // returns [ 10, 109 ]
56+
*
57+
* @example
58+
* var shape = [ 10, 10 ];
59+
* var strides = [ -1, -10 ];
60+
* var offset = 99;
61+
*
62+
* var idx = minmaxViewBufferIndex( shape, strides, offset );
63+
* // returns [ 0, 99 ]
64+
*/
65+
declare function minmaxViewBufferIndex( shape: ArrayLike<number>, strides: ArrayLike<number>, offset: number ): Array<number>; // tslint-disable-line max-line-length
66+
67+
68+
// EXPORTS //
69+
70+
export = minmaxViewBufferIndex;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import minmaxViewBufferIndex = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an array of numbers...
25+
{
26+
minmaxViewBufferIndex( [ 10, 10 ], [ 10, 1 ], 10 ); // $ExpectType number[]
27+
}
28+
29+
// The function does not compile if provided a first argument which is not an array-like object containing numbers...
30+
{
31+
const strides = [ 10, 1 ];
32+
const offset = 10;
33+
minmaxViewBufferIndex( true, strides, offset ); // $ExpectError
34+
minmaxViewBufferIndex( false, strides, offset ); // $ExpectError
35+
minmaxViewBufferIndex( null, strides, offset ); // $ExpectError
36+
minmaxViewBufferIndex( undefined, strides, offset ); // $ExpectError
37+
minmaxViewBufferIndex( '5', strides, offset ); // $ExpectError
38+
minmaxViewBufferIndex( [ '1', '2' ], strides, offset ); // $ExpectError
39+
minmaxViewBufferIndex( {}, strides, offset ); // $ExpectError
40+
minmaxViewBufferIndex( ( x: number ): number => x, strides, offset ); // $ExpectError
41+
}
42+
43+
// The function does not compile if provided a second argument which is not an array-like object containing numbers...
44+
{
45+
const shape = [ 10, 10 ];
46+
const offset = 10;
47+
minmaxViewBufferIndex( shape, true, offset ); // $ExpectError
48+
minmaxViewBufferIndex( shape, false, offset ); // $ExpectError
49+
minmaxViewBufferIndex( shape, null, offset ); // $ExpectError
50+
minmaxViewBufferIndex( shape, undefined, offset ); // $ExpectError
51+
minmaxViewBufferIndex( shape, '5', offset ); // $ExpectError
52+
minmaxViewBufferIndex( shape, [ '1', '2' ], offset ); // $ExpectError
53+
minmaxViewBufferIndex( shape, {}, offset ); // $ExpectError
54+
minmaxViewBufferIndex( shape, ( x: number ): number => x, offset ); // $ExpectError
55+
}
56+
57+
// The function does not compile if provided a third argument which is not a number...
58+
{
59+
const shape = [ 10, 10 ];
60+
const strides = [ 10, 1 ];
61+
minmaxViewBufferIndex( shape, strides, true ); // $ExpectError
62+
minmaxViewBufferIndex( shape, strides, false ); // $ExpectError
63+
minmaxViewBufferIndex( shape, strides, null ); // $ExpectError
64+
minmaxViewBufferIndex( shape, strides, undefined ); // $ExpectError
65+
minmaxViewBufferIndex( shape, strides, '5' ); // $ExpectError
66+
minmaxViewBufferIndex( shape, strides, [ '1', '2' ] ); // $ExpectError
67+
minmaxViewBufferIndex( shape, strides, {} ); // $ExpectError
68+
minmaxViewBufferIndex( shape, strides, ( x: number ): number => x ); // $ExpectError
69+
}
70+
71+
// The function does not compile if provided insufficient arguments...
72+
{
73+
minmaxViewBufferIndex(); // $ExpectError
74+
minmaxViewBufferIndex( [ 10, 10 ] ); // $ExpectError
75+
minmaxViewBufferIndex( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError
76+
}

lib/node_modules/@stdlib/ndarray/base/minmax-view-buffer-index/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"src": "./src",
2424
"test": "./test"
2525
},
26+
"types": "./docs/types",
2627
"scripts": {},
2728
"homepage": "https://github.com/stdlib-js/stdlib",
2829
"repository": {

0 commit comments

Comments
 (0)