Skip to content

Commit a31dfc1

Browse files
committed
Add Typescript definitions
1 parent a77f7a8 commit a31dfc1

6 files changed

Lines changed: 190 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
/**
22+
* Returns the index offset which specifies the location of the first indexed value in a multidimensional array based on a stride array.
23+
*
24+
* @param shape - array shape
25+
* @param strides - stride array
26+
* @returns offset - offset
27+
*
28+
* @example
29+
* var shape = [ 2, 3, 10 ];
30+
* var strides = [ 30, -10, 1 ];
31+
*
32+
* var offset = strides2offset( shape, strides );
33+
* // returns 20
34+
*/
35+
declare function strides2offset( shape: Array<number>, strides: Array<number> ): number;
36+
37+
38+
// EXPORTS //
39+
40+
export = strides2offset;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 strides2offset = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
strides2offset( [ 2, 3, 10 ], [ 30, -10, 1 ] ); // $ExpectType number
27+
}
28+
29+
// The function does not compile if provided values other than two number arrays...
30+
{
31+
const shape = [ 2, 3, 10 ];
32+
const strides = [ 30, -10, 1 ];
33+
strides2offset( true, strides ); // $ExpectError
34+
strides2offset( false, strides ); // $ExpectError
35+
strides2offset( '5', strides ); // $ExpectError
36+
strides2offset( 123, strides ); // $ExpectError
37+
strides2offset( {}, strides ); // $ExpectError
38+
strides2offset( ( x: number ): number => x, strides ); // $ExpectError
39+
40+
strides2offset( shape, true ); // $ExpectError
41+
strides2offset( shape, false ); // $ExpectError
42+
strides2offset( shape, '5' ); // $ExpectError
43+
strides2offset( shape, 123 ); // $ExpectError
44+
strides2offset( shape, {} ); // $ExpectError
45+
strides2offset( shape, ( x: number ): number => x ); // $ExpectError
46+
47+
strides2offset( [], true ); // $ExpectError
48+
strides2offset( {}, false ); // $ExpectError
49+
strides2offset( false, '5' ); // $ExpectError
50+
strides2offset( {}, 123 ); // $ExpectError
51+
strides2offset( '5', ( x: number ): number => x ); // $ExpectError
52+
}
53+
54+
// The function does not compile if provided insufficient arguments...
55+
{
56+
strides2offset(); // $ExpectError
57+
strides2offset( 3 ); // $ExpectError
58+
}

lib/node_modules/@stdlib/ndarray/base/strides2offset/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
/**
22+
* Determines the order of a multidimensional array based on a provided stride array.
23+
*
24+
* @param strides - stride array
25+
* @returns order
26+
*
27+
* @example
28+
* var order = strides2order( [ 2, 1 ] );
29+
* // returns 1
30+
*
31+
* @example
32+
* var order = strides2order( [ 1, 2 ] );
33+
* // returns 2
34+
*
35+
* @example
36+
* var order = strides2order( [ 1, 1, 1 ] );
37+
* // returns 3
38+
*
39+
* @example
40+
* var order = strides2order( [ 2, 3, 1 ] );
41+
* // returns 0
42+
*/
43+
declare function strides2order( strides: Array<number> ): number;
44+
45+
46+
// EXPORTS //
47+
48+
export = strides2order;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 strides2order = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
strides2order( [ 2, 1 ] ); // $ExpectType number
27+
}
28+
29+
// The function does not compile if provided a value other than an array of numbers...
30+
{
31+
strides2order( true ); // $ExpectError
32+
strides2order( false ); // $ExpectError
33+
strides2order( '5' ); // $ExpectError
34+
strides2order( 123 ); // $ExpectError
35+
strides2order( {} ); // $ExpectError
36+
strides2order( ( x: number ): number => x ); // $ExpectError
37+
}
38+
39+
// The function does not compile if provided insufficient arguments...
40+
{
41+
strides2order(); // $ExpectError
42+
}

lib/node_modules/@stdlib/ndarray/base/strides2order/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lib": "./lib",
2222
"test": "./test"
2323
},
24+
"types": "./docs/types",
2425
"scripts": {},
2526
"homepage": "https://github.com/stdlib-js/stdlib",
2627
"repository": {

0 commit comments

Comments
 (0)