Skip to content

Commit 906157d

Browse files
committed
Auto-generated commit
1 parent a42ebf7 commit 906157d

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380

381381
### Bug Fixes
382382

383+
- [`6d74243`](https://github.com/stdlib-js/stdlib/commit/6d742438beb8e7fe0de4ecfbc82083da16a0a83c) - ensure correct type when providing a `dtype` option
383384
- [`57a9400`](https://github.com/stdlib-js/stdlib/commit/57a9400329d0570d2b25ad6b87d4d9a74d7fc28b) - avoid strict equality check
384385
- [`d5e1c28`](https://github.com/stdlib-js/stdlib/commit/d5e1c28e6821d21da0b79090ebd3cf903f036aae) - maintain floating-point precision
385386
- [`8983f46`](https://github.com/stdlib-js/stdlib/commit/8983f46c72781a991814dcf9a6e08db27cd12e39) - use correct variable
@@ -531,6 +532,7 @@ A total of 24 issues were closed in this release:
531532

532533
<details>
533534

535+
- [`6d74243`](https://github.com/stdlib-js/stdlib/commit/6d742438beb8e7fe0de4ecfbc82083da16a0a83c) - **fix:** ensure correct type when providing a `dtype` option _(by Athan Reines)_
534536
- [`0ed631d`](https://github.com/stdlib-js/stdlib/commit/0ed631d96dae3b796882c441f79505275afbc4c0) - **feat:** add `dtype` option support in `ndarray/flatten` [(#8091)](https://github.com/stdlib-js/stdlib/pull/8091) _(by Muhammad Haris, Athan Reines)_
535537
- [`724283b`](https://github.com/stdlib-js/stdlib/commit/724283b0bc5d2eb8bf48491c954c6a119330c1f5) - **feat:** add `ndarray/base/nullary-strided1d-dispatch-factory` [(#7828)](https://github.com/stdlib-js/stdlib/pull/7828) _(by Muhammad Haris, Athan Reines, stdlib-bot)_
536538
- [`2743732`](https://github.com/stdlib-js/stdlib/commit/27437323cb1d22c53c91f152d6d05153630bc123) - **docs:** fix description _(by Athan Reines)_

flatten/docs/types/index.d.ts

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { ndarray, Order, DataType } from '@stdlib/types/ndarray';
23+
import { ndarray, typedndarray, Order, DataTypeMap } from '@stdlib/types/ndarray';
2424

2525
/**
26-
* Interface defining function options.
26+
* Interface defining "base" function options.
2727
*/
28-
interface Options {
28+
interface BaseOptions {
2929
/**
3030
* Maximum number of dimensions to flatten.
3131
*
@@ -50,16 +50,47 @@ interface Options {
5050
* - Default: 'row-major'.
5151
*/
5252
order?: Order | 'same' | 'any';
53+
}
5354

55+
/**
56+
* Function options.
57+
*/
58+
type Options<U> = BaseOptions & {
5459
/**
5560
* 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.
6061
*/
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;
6394

6495
/**
6596
* Returns a flattened copy of an input ndarray.
@@ -72,6 +103,7 @@ interface Options {
72103
* @param options - function options
73104
* @param options.depth - maximum number of dimensions to flatten
74105
* @param options.order - order in which input ndarray elements should be flattened
106+
* @param options.dtype - output ndarray data type
75107
* @returns output ndarray
76108
*
77109
* @example
@@ -87,7 +119,7 @@ interface Options {
87119
* var arr = ndarray2array( y );
88120
* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
89121
*/
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];
91123

92124

93125
// EXPORTS //

flatten/docs/types/test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import flatten = require( './index' );
3131
flatten( zeros( 'float64', [ 2, 2, 2 ], 'row-major' ), {} ); // $ExpectType float64ndarray
3232
flatten( zeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), {} ); // $ExpectType complex128ndarray
3333
flatten( zeros( 'generic', [ 2, 2, 2 ], 'row-major' ), {} ); // $ExpectType genericndarray<number>
34+
35+
flatten( zeros( 'float64', [ 2, 2, 2 ], 'row-major' ), { 'dtype': 'float32' } ); // $ExpectType float32ndarray
36+
flatten( zeros( 'int32', [ 2, 2, 2 ], 'row-major' ), { 'dtype': 'float64' } ); // $ExpectType float64ndarray
37+
flatten( zeros( 'int32', [ 2, 2, 2 ], 'row-major' ), { 'dtype': 'generic' } ); // $ExpectType genericndarray<number>
3438
}
3539

3640
// The compiler throws an error if the function is provided a first argument which is not an ndarray-like object...

0 commit comments

Comments
 (0)