Skip to content

Commit 0465274

Browse files
committed
Add Typescript definition
1 parent 013afbe commit 0465274

File tree

3 files changed

+414
-0
lines changed

3 files changed

+414
-0
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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+
/// <reference types="node"/>
23+
24+
import { Buffer } from 'buffer';
25+
import { ArrayLike, TypedArray } from '@stdlib/types/array';
26+
import { DataType, ndarray, Mode, Order } from '@stdlib/types/ndarray';
27+
28+
/**
29+
* Interface defining function options.
30+
*/
31+
interface Options {
32+
/**
33+
* Underlying storage data type (if the input data is not of the same type, this option specifies the data type to which to cast the input data) (default: 'float64').
34+
*/
35+
dtype?: DataType;
36+
37+
/**
38+
* Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major').
39+
*/
40+
order?: Order;
41+
42+
/**
43+
* Array shape.
44+
*/
45+
shape?: ArrayLike<number>;
46+
47+
/**
48+
* Specifies how to handle indices which exceed array dimensions (default: 'throw').
49+
*/
50+
mode?: Mode;
51+
52+
/**
53+
* Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']).
54+
*/
55+
submode?: Array<string>;
56+
57+
/**
58+
* Boolean indicating whether to copy source data to a new data buffer (default: false).
59+
*/
60+
copy?: boolean;
61+
62+
/**
63+
* Boolean indicating whether to automatically flatten generic array data sources (default: true).
64+
*/
65+
flatten?: boolean;
66+
67+
/**
68+
* Minimum number of dimensions (default: 0).
69+
*/
70+
ndmin?: number;
71+
72+
/**
73+
* Casting rule used to determine what constitutes an acceptable cast (default: 'safe').
74+
*/
75+
casting?: string;
76+
}
77+
78+
/**
79+
* Array or typed array.
80+
*/
81+
type ArrayOrBufferOrTypedArray = Array<any> | TypedArray | Buffer | null;
82+
83+
/**
84+
* Returns a multidimensional array.
85+
*
86+
* @param options - function options
87+
* @param options.buffer - data source
88+
* @param options.dtype - underlying storage data type (if the input data is not of the same type, this option specifies the data type to which to cast the input data) (default: 'float64')
89+
* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major')
90+
* @param options.shape - array shape
91+
* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw')
92+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw'])
93+
* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false)
94+
* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true)
95+
* @param options.ndmin - minimum number of dimensions (default: 0)
96+
* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe')
97+
* @throws must provide valid options
98+
* @throws must provide either an array shape, data source, or both
99+
* @throws invalid cast
100+
* @throws data source must be compatible with specified meta data
101+
* @returns ndarray instance
102+
*
103+
* @example
104+
* var opts = {
105+
* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ],
106+
* 'dtype': 'generic',
107+
* 'flatten': false
108+
* };
109+
*
110+
* var arr = array( opts );
111+
* // returns <ndarray>
112+
*
113+
* var v = arr.get( 0 );
114+
* // returns [ 1, 2 ]
115+
*/
116+
declare function array( options: Options ): ndarray;
117+
118+
/**
119+
* Returns a multidimensional array.
120+
*
121+
* @param buffer - data source
122+
* @param options - function options
123+
* @param options.buffer - data source
124+
* @param options.dtype - underlying storage data type (if the input data is not of the same type, this option specifies the data type to which to cast the input data) (default: 'float64')
125+
* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major')
126+
* @param options.shape - array shape
127+
* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw')
128+
* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw'])
129+
* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false)
130+
* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true)
131+
* @param options.ndmin - minimum number of dimensions (default: 0)
132+
* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe')
133+
* @throws must provide valid options
134+
* @throws must provide either an array shape, data source, or both
135+
* @throws invalid cast
136+
* @throws data source must be compatible with specified meta data
137+
* @returns ndarray instance
138+
*
139+
* @example
140+
* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );
141+
* // returns <ndarray>
142+
*
143+
* var v = arr.get( 0, 0 );
144+
* // returns 1
145+
*
146+
* @example
147+
* var opts = {
148+
* 'dtype': 'generic',
149+
* 'flatten': false
150+
* };
151+
*
152+
* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts );
153+
* // returns <ndarray>
154+
*
155+
* var v = arr.get( 0 );
156+
* // returns [ 1, 2 ]
157+
*
158+
* @example
159+
* var Float64Array = require( '@stdlib/array/float64' );
160+
*
161+
* var opts = {
162+
* 'shape': [ 2, 2 ]
163+
* };
164+
*
165+
* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts );
166+
* // returns <ndarray>
167+
*
168+
* var v = arr.get( 0, 0 );
169+
* // returns 1.0
170+
*/
171+
declare function array( buffer: ArrayOrBufferOrTypedArray, options?: Options ): ndarray; // tslint-disable-line max-line-length
172+
173+
174+
// EXPORTS //
175+
176+
export = array;

0 commit comments

Comments
 (0)