2020
2121/// <reference types="@stdlib/types"/>
2222
23- import { AnyArray , Collection , Complex128Array , Complex64Array , DataType } from '@stdlib/types/array' ;
24-
25- /**
26- * Converts an array to a `Float64Array`.
27- *
28- * @param x - array to convert
29- * @param dtype - output data type
30- * @returns output array
31- *
32- * @example
33- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
34- * var out = convert( arr, 'float64' );
35- * // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
36- */
37- declare function convert ( x : Collection , dtype : 'float64' ) : Float64Array ;
38-
39- /**
40- * Converts an array to a `Float32Array`.
41- *
42- * @param x - array to convert
43- * @param dtype - output data type
44- * @returns output array
45- *
46- * @example
47- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
48- * var out = convert( arr, 'float32' );
49- * // returns <Float32Array>[ 1.0, 2.0, 3.0, 4.0 ]
50- */
51- declare function convert ( x : Collection , dtype : 'float32' ) : Float32Array ;
52-
53- /**
54- * Converts an array to an `Int32Array`.
55- *
56- * @param x - array to convert
57- * @param dtype - output data type
58- * @returns output array
59- *
60- * @example
61- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
62- * var out = convert( arr, 'int32' );
63- * // returns <Int32Array>[ 1, 2, 3, 4 ]
64- */
65- declare function convert ( x : Collection , dtype : 'int32' ) : Int32Array ;
66-
67- /**
68- * Converts an array to an `Int16Array`.
69- *
70- * @param x - array to convert
71- * @param dtype - output data type
72- * @returns output array
73- *
74- * @example
75- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
76- * var out = convert( arr, 'int16' );
77- * // returns <Int16Array>[ 1, 2, 3, 4 ]
78- */
79- declare function convert ( x : Collection , dtype : 'int16' ) : Int16Array ;
80-
81- /**
82- * Converts an array to an `Int8Array`.
83- *
84- * @param x - array to convert
85- * @param dtype - output data type
86- * @returns output array
87- *
88- * @example
89- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
90- * var out = convert( arr, 'int8' );
91- * // returns <Int8Array>[ 1, 2, 3, 4 ]
92- */
93- declare function convert ( x : Collection , dtype : 'int8' ) : Int8Array ;
94-
95- /**
96- * Converts an array to a `Uint32Array`.
97- *
98- * @param x - array to convert
99- * @param dtype - output data type
100- * @returns output array
101- *
102- * @example
103- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
104- * var out = convert( arr, 'uint32' );
105- * // returns <Uint32Array>[ 1, 2, 3, 4 ]
106- */
107- declare function convert ( x : Collection , dtype : 'uint32' ) : Uint32Array ;
108-
109- /**
110- * Converts an array to a `Uint16Array`.
111- *
112- * @param x - array to convert
113- * @param dtype - output data type
114- * @returns output array
115- *
116- * @example
117- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
118- * var out = convert( arr, 'uint16' );
119- * // returns <Uint16Array>[ 1, 2, 3, 4 ]
120- */
121- declare function convert ( x : Collection , dtype : 'uint16' ) : Uint16Array ;
122-
123- /**
124- * Converts an array to a `Uint8Array`.
125- *
126- * @param x - array to convert
127- * @param dtype - output data type
128- * @returns output array
129- *
130- * @example
131- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
132- * var out = convert( arr, 'uint8' );
133- * // returns <Uint8Array>[ 1, 2, 3, 4 ]
134- */
135- declare function convert ( x : Collection , dtype : 'uint8' ) : Uint8Array ;
136-
137- /**
138- * Converts an array to a `Uint8ClampedArray`.
139- *
140- * @param x - array to convert
141- * @param dtype - output data type
142- * @returns output array
143- *
144- * @example
145- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
146- * var out = convert( arr, 'uint8c' );
147- * // returns <Uint8ClampedArray>[ 1, 2, 3, 4 ]
148- */
149- declare function convert ( x : Collection , dtype : 'uint8c' ) : Uint8ClampedArray ;
150-
151- /**
152- * Converts an array to a `Complex128Array`.
153- *
154- * @param x - array to convert
155- * @param dtype - output data type
156- * @returns output array
157- *
158- * @example
159- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
160- * var out = convert( arr, 'complex128' );
161- * // returns <Complex128>
162- */
163- declare function convert ( x : Collection , dtype : 'complex128' ) : Complex128Array ;
164-
165- /**
166- * Converts an array to a `Complex64Array`.
167- *
168- * @param x - array to convert
169- * @param dtype - output data type
170- * @returns output array
171- *
172- * @example
173- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
174- * var out = convert( arr, 'complex64' );
175- * // returns <Complex64>
176- */
177- declare function convert ( x : Collection , dtype : 'complex64' ) : Complex64Array ;
178-
179- /**
180- * Converts an array to an `Array`.
181- *
182- * @param x - array to convert
183- * @param dtype - output data type
184- * @returns output array
185- *
186- * @example
187- * var arr = [ 1.0, 2.0, 3.0, 4.0 ];
188- * var out = convert( arr, 'generic' );
189- * // returns [ 1.0, 2.0, 3.0, 4.0 ]
190- */
191- declare function convert ( x : Collection , dtype : 'generic' ) : Array < any > ;
23+ import { Collection , DataTypeMap } from '@stdlib/types/array' ;
19224
19325/**
19426* Converts an array to an array of a different data type.
@@ -202,7 +34,7 @@ declare function convert( x: Collection, dtype: 'generic' ): Array<any>;
20234* var out = convert( arr, 'float64' );
20335* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
20436*/
205- declare function convert ( x : Collection , dtype : DataType ) : AnyArray ;
37+ declare function convert < T , U extends keyof DataTypeMap < T > > ( x : Collection < T > , dtype : U ) : DataTypeMap < T > [ U ] ;
20638
20739
20840// EXPORTS //
0 commit comments