20
20
21
21
/// <reference types="@stdlib/types"/>
22
22
23
- import { typedndarray , genericndarray , Order } from '@stdlib/types/ndarray' ;
23
+ import { typedndarray , genericndarray , Order , DataTypeMap } from '@stdlib/types/ndarray' ;
24
24
import { ComplexLike } from '@stdlib/types/complex' ;
25
25
26
26
/**
@@ -68,9 +68,9 @@ type Ternary<T, U, V, ThisArg> = ( this: ThisArg, value: T, indices: Array<numbe
68
68
type Callback < T , U , V , ThisArg > = Nullary < V , ThisArg > | Unary < T , V , ThisArg > | Binary < T , V , ThisArg > | Ternary < T , U , V , ThisArg > ;
69
69
70
70
/**
71
- * Interface defining function options.
71
+ * Interface defining "base" function options.
72
72
*/
73
- interface Options {
73
+ interface BaseOptions {
74
74
/**
75
75
* Maximum number of dimensions to flatten.
76
76
*
@@ -97,6 +97,16 @@ interface Options {
97
97
order ?: Order | 'same' | 'any' ;
98
98
}
99
99
100
+ /**
101
+ * Function options.
102
+ */
103
+ type Options < U > = BaseOptions & {
104
+ /**
105
+ * Output ndarray data type.
106
+ */
107
+ dtype : U ;
108
+ } ;
109
+
100
110
/**
101
111
* Flattens an ndarray according to a callback function.
102
112
*
@@ -232,6 +242,7 @@ declare function flattenBy<T = unknown, U extends genericndarray<T> = genericnda
232
242
* @param options - function options
233
243
* @param options.depth - maximum number of dimensions to flatten
234
244
* @param options.order - order in which input ndarray elements should be flattened
245
+ * @param options.dtype - output ndarray data type
235
246
* @param fcn - callback function
236
247
* @param thisArg - callback execution context
237
248
* @returns output ndarray
@@ -263,7 +274,7 @@ declare function flattenBy<T = unknown, U extends genericndarray<T> = genericnda
263
274
* var arr = ndarray2array( y );
264
275
* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ]
265
276
*/
266
- declare function flattenBy < T extends typedndarray < number > = typedndarray < number > , ThisArg = unknown > ( x : T , options : Options , fcn : Callback < number , T , number , ThisArg > , thisArg ?: ThisParameterType < Callback < number , T , number , ThisArg > > ) : T ;
277
+ declare function flattenBy < T extends typedndarray < number > = typedndarray < number > , ThisArg = unknown > ( x : T , options : BaseOptions , fcn : Callback < number , T , number , ThisArg > , thisArg ?: ThisParameterType < Callback < number , T , number , ThisArg > > ) : T ;
267
278
268
279
/**
269
280
* Flattens an ndarray according to a callback function.
@@ -272,6 +283,7 @@ declare function flattenBy<T extends typedndarray<number> = typedndarray<number>
272
283
* @param options - function options
273
284
* @param options.depth - maximum number of dimensions to flatten
274
285
* @param options.order - order in which input ndarray elements should be flattened
286
+ * @param options.dtype - output ndarray data type
275
287
* @param fcn - callback function
276
288
* @param thisArg - callback execution context
277
289
* @returns output ndarray
@@ -300,7 +312,7 @@ declare function flattenBy<T extends typedndarray<number> = typedndarray<number>
300
312
* var y = flattenBy( x, opts, identity );
301
313
* // returns <ndarray>
302
314
*/
303
- declare function flattenBy < T extends ComplexLike = ComplexLike , U extends typedndarray < T > = typedndarray < T > , ThisArg = unknown > ( x : U , options : Options , fcn : Callback < T , U , T , ThisArg > , thisArg ?: ThisParameterType < Callback < T , U , T , ThisArg > > ) : U ;
315
+ declare function flattenBy < T extends ComplexLike = ComplexLike , U extends typedndarray < T > = typedndarray < T > , ThisArg = unknown > ( x : U , options : BaseOptions , fcn : Callback < T , U , T , ThisArg > , thisArg ?: ThisParameterType < Callback < T , U , T , ThisArg > > ) : U ;
304
316
305
317
/**
306
318
* Flattens an ndarray according to a callback function.
@@ -309,6 +321,7 @@ declare function flattenBy<T extends ComplexLike = ComplexLike, U extends typedn
309
321
* @param options - function options
310
322
* @param options.depth - maximum number of dimensions to flatten
311
323
* @param options.order - order in which input ndarray elements should be flattened
324
+ * @param options.dtype - output ndarray data type
312
325
* @param fcn - callback function
313
326
* @param thisArg - callback execution context
314
327
* @returns output ndarray
@@ -340,7 +353,7 @@ declare function flattenBy<T extends ComplexLike = ComplexLike, U extends typedn
340
353
* var arr = ndarray2array( y );
341
354
* // returns [ false, true, false, true, false, true ]
342
355
*/
343
- declare function flattenBy < T extends typedndarray < boolean > = typedndarray < boolean > , ThisArg = unknown > ( x : T , options : Options , fcn : Callback < boolean , T , boolean , ThisArg > , thisArg ?: ThisParameterType < Callback < boolean , T , boolean , ThisArg > > ) : T ;
356
+ declare function flattenBy < T extends typedndarray < boolean > = typedndarray < boolean > , ThisArg = unknown > ( x : T , options : BaseOptions , fcn : Callback < boolean , T , boolean , ThisArg > , thisArg ?: ThisParameterType < Callback < boolean , T , boolean , ThisArg > > ) : T ;
344
357
345
358
/**
346
359
* Flattens an ndarray according to a callback function.
@@ -349,6 +362,7 @@ declare function flattenBy<T extends typedndarray<boolean> = typedndarray<boolea
349
362
* @param options - function options
350
363
* @param options.depth - maximum number of dimensions to flatten
351
364
* @param options.order - order in which input ndarray elements should be flattened
365
+ * @param options.dtype - output ndarray data type
352
366
* @param fcn - callback function
353
367
* @param thisArg - callback execution context
354
368
* @returns output ndarray
@@ -379,7 +393,48 @@ declare function flattenBy<T extends typedndarray<boolean> = typedndarray<boolea
379
393
* var arr = ndarray2array( y );
380
394
* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ]
381
395
*/
382
- declare function flattenBy < T = unknown , U extends genericndarray < T > = genericndarray < T > , V = unknown , W extends genericndarray < V > = genericndarray < V > , ThisArg = unknown > ( x : U , options : Options , fcn : Callback < T , U , V , ThisArg > , thisArg ?: ThisParameterType < Callback < T , U , V , ThisArg > > ) : W ;
396
+ declare function flattenBy < T = unknown , U extends genericndarray < T > = genericndarray < T > , V = unknown , W extends genericndarray < V > = genericndarray < V > , ThisArg = unknown > ( x : U , options : BaseOptions , fcn : Callback < T , U , V , ThisArg > , thisArg ?: ThisParameterType < Callback < T , U , V , ThisArg > > ) : W ;
397
+
398
+ /**
399
+ * Flattens an ndarray according to a callback function.
400
+ *
401
+ * @param x - input ndarray
402
+ * @param options - function options
403
+ * @param options.depth - maximum number of dimensions to flatten
404
+ * @param options.order - order in which input ndarray elements should be flattened
405
+ * @param options.dtype - output ndarray data type
406
+ * @param fcn - callback function
407
+ * @param thisArg - callback execution context
408
+ * @returns output ndarray
409
+ *
410
+ * @example
411
+ * var Float64Array = require( '@stdlib/array/float64' );
412
+ * var ndarray = require( '@stdlib/ndarray/ctor' );
413
+ * var ndarray2array = require( '@stdlib/ndarray/to-array' );
414
+ *
415
+ * function scale( value ) {
416
+ * return value * 2.0;
417
+ * }
418
+ *
419
+ * var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
420
+ * var shape = [ 3, 1, 2 ];
421
+ * var strides = [ 2, 2, 1 ];
422
+ * var offset = 0;
423
+ *
424
+ * var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );
425
+ * // return <ndarray>
426
+ *
427
+ * var opts = {
428
+ * 'depth': 2
429
+ * };
430
+ *
431
+ * var y = flattenBy( x, opts, scale );
432
+ * // returns <ndarray>
433
+ *
434
+ * var arr = ndarray2array( y );
435
+ * // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ]
436
+ */
437
+ declare function flattenBy < T = unknown , U extends typedndarray < T > | genericndarray < T > = typedndarray < T > , V = unknown , W extends keyof DataTypeMap < T > = 'generic' , ThisArg = unknown > ( x : U , options : Options < W > , fcn : Callback < T , U , V , ThisArg > , thisArg ?: ThisParameterType < Callback < T , U , V , ThisArg > > ) : DataTypeMap < V > [ W ] ;
383
438
384
439
385
440
// EXPORTS //
0 commit comments