2020
2121/// <reference types="@stdlib/types"/>
2222
23- import { typedndarray , genericndarray , Order } from '@stdlib/types/ndarray' ;
23+ import { typedndarray , genericndarray , Order , DataTypeMap } from '@stdlib/types/ndarray' ;
2424import { ComplexLike } from '@stdlib/types/complex' ;
2525
2626/**
@@ -68,9 +68,9 @@ type Ternary<T, U, V, ThisArg> = ( this: ThisArg, value: T, indices: Array<numbe
6868type Callback < T , U , V , ThisArg > = Nullary < V , ThisArg > | Unary < T , V , ThisArg > | Binary < T , V , ThisArg > | Ternary < T , U , V , ThisArg > ;
6969
7070/**
71- * Interface defining function options.
71+ * Interface defining "base" function options.
7272*/
73- interface Options {
73+ interface BaseOptions {
7474 /**
7575 * Maximum number of dimensions to flatten.
7676 *
@@ -97,6 +97,16 @@ interface Options {
9797 order ?: Order | 'same' | 'any' ;
9898}
9999
100+ /**
101+ * Function options.
102+ */
103+ type Options < U > = BaseOptions & {
104+ /**
105+ * Output ndarray data type.
106+ */
107+ dtype : U ;
108+ } ;
109+
100110/**
101111* Flattens an ndarray according to a callback function.
102112*
@@ -232,6 +242,7 @@ declare function flattenBy<T = unknown, U extends genericndarray<T> = genericnda
232242* @param options - function options
233243* @param options.depth - maximum number of dimensions to flatten
234244* @param options.order - order in which input ndarray elements should be flattened
245+ * @param options.dtype - output ndarray data type
235246* @param fcn - callback function
236247* @param thisArg - callback execution context
237248* @returns output ndarray
@@ -263,7 +274,7 @@ declare function flattenBy<T = unknown, U extends genericndarray<T> = genericnda
263274* var arr = ndarray2array( y );
264275* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ]
265276*/
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 ;
267278
268279/**
269280* Flattens an ndarray according to a callback function.
@@ -272,6 +283,7 @@ declare function flattenBy<T extends typedndarray<number> = typedndarray<number>
272283* @param options - function options
273284* @param options.depth - maximum number of dimensions to flatten
274285* @param options.order - order in which input ndarray elements should be flattened
286+ * @param options.dtype - output ndarray data type
275287* @param fcn - callback function
276288* @param thisArg - callback execution context
277289* @returns output ndarray
@@ -300,7 +312,7 @@ declare function flattenBy<T extends typedndarray<number> = typedndarray<number>
300312* var y = flattenBy( x, opts, identity );
301313* // returns <ndarray>
302314*/
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 ;
304316
305317/**
306318* Flattens an ndarray according to a callback function.
@@ -309,6 +321,7 @@ declare function flattenBy<T extends ComplexLike = ComplexLike, U extends typedn
309321* @param options - function options
310322* @param options.depth - maximum number of dimensions to flatten
311323* @param options.order - order in which input ndarray elements should be flattened
324+ * @param options.dtype - output ndarray data type
312325* @param fcn - callback function
313326* @param thisArg - callback execution context
314327* @returns output ndarray
@@ -340,7 +353,7 @@ declare function flattenBy<T extends ComplexLike = ComplexLike, U extends typedn
340353* var arr = ndarray2array( y );
341354* // returns [ false, true, false, true, false, true ]
342355*/
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 ;
344357
345358/**
346359* Flattens an ndarray according to a callback function.
@@ -349,6 +362,7 @@ declare function flattenBy<T extends typedndarray<boolean> = typedndarray<boolea
349362* @param options - function options
350363* @param options.depth - maximum number of dimensions to flatten
351364* @param options.order - order in which input ndarray elements should be flattened
365+ * @param options.dtype - output ndarray data type
352366* @param fcn - callback function
353367* @param thisArg - callback execution context
354368* @returns output ndarray
@@ -379,7 +393,48 @@ declare function flattenBy<T extends typedndarray<boolean> = typedndarray<boolea
379393* var arr = ndarray2array( y );
380394* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ]
381395*/
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 ] ;
383438
384439
385440// EXPORTS //
0 commit comments