20
20
21
21
/// <reference types="@stdlib/types"/>
22
22
23
- import { ndarray , Order , DataType } from '@stdlib/types/ndarray' ;
23
+ import { ndarray , typedndarray , Order , DataTypeMap } from '@stdlib/types/ndarray' ;
24
24
25
25
/**
26
- * Interface defining function options.
26
+ * Interface defining "base" function options.
27
27
*/
28
- interface Options {
28
+ interface BaseOptions {
29
29
/**
30
30
* Maximum number of dimensions to flatten.
31
31
*
@@ -50,16 +50,47 @@ interface Options {
50
50
* - Default: 'row-major'.
51
51
*/
52
52
order ?: Order | 'same' | 'any' ;
53
+ }
53
54
55
+ /**
56
+ * Function options.
57
+ */
58
+ type Options < U > = BaseOptions & {
54
59
/**
55
60
* Output ndarray data type.
56
- *
57
- * ## Notes
58
- *
59
- * - By default, the function returns an ndarray having the same data type as a provided input ndarray.
60
61
*/
61
- dtype ?: DataType ;
62
- }
62
+ dtype : U ;
63
+ } ;
64
+
65
+ /**
66
+ * Returns a flattened copy of an input ndarray.
67
+ *
68
+ * ## Notes
69
+ *
70
+ * - The function **always** returns a copy of input ndarray data, even when an input ndarray already has the desired number of dimensions.
71
+ * - By default, the function returns an ndarray having the same data type as a provided input ndarray.
72
+ *
73
+ * @param x - input ndarray
74
+ * @param options - function options
75
+ * @param options.depth - maximum number of dimensions to flatten
76
+ * @param options.order - order in which input ndarray elements should be flattened
77
+ * @param options.dtype - output ndarray data type
78
+ * @returns output ndarray
79
+ *
80
+ * @example
81
+ * var array = require( '@stdlib/ndarray/array' );
82
+ * var ndarray2array = require( '@stdlib/ndarray/to-array' );
83
+ *
84
+ * var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] );
85
+ * // return <ndarray>
86
+ *
87
+ * var y = flatten( x );
88
+ * // returns <ndarray>
89
+ *
90
+ * var arr = ndarray2array( y );
91
+ * // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
92
+ */
93
+ declare function flatten < T extends ndarray > ( x : T , options ?: BaseOptions ) : T ;
63
94
64
95
/**
65
96
* Returns a flattened copy of an input ndarray.
@@ -72,6 +103,7 @@ interface Options {
72
103
* @param options - function options
73
104
* @param options.depth - maximum number of dimensions to flatten
74
105
* @param options.order - order in which input ndarray elements should be flattened
106
+ * @param options.dtype - output ndarray data type
75
107
* @returns output ndarray
76
108
*
77
109
* @example
@@ -87,7 +119,7 @@ interface Options {
87
119
* var arr = ndarray2array( y );
88
120
* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
89
121
*/
90
- declare function flatten < T extends ndarray > ( x : T , options ? : Options ) : T ;
122
+ declare function flatten < T = unknown , U extends keyof DataTypeMap < T > = 'generic' > ( x : typedndarray < T > , options : Options < U > ) : DataTypeMap < T > [ U ] ;
91
123
92
124
93
125
// EXPORTS //
0 commit comments