Skip to content

Commit d4035c9

Browse files
committed
Auto-generated commit
1 parent f056f11 commit d4035c9

File tree

11 files changed

+2625
-0
lines changed

11 files changed

+2625
-0
lines changed

CHANGELOG.md

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

1111
### Features
1212

13+
- [`7944b3f`](https://github.com/stdlib-js/stdlib/commit/7944b3f8ddcaf5f073dd6f304c30d6f385f94d23) - add `ndarray/flatten` [(#8021)](https://github.com/stdlib-js/stdlib/pull/8021)
1314
- [`11c01f2`](https://github.com/stdlib-js/stdlib/commit/11c01f20be688370014f77248a2f6cf423dfbdc2) - add `flattenShape` to namespace
1415
- [`83e21a1`](https://github.com/stdlib-js/stdlib/commit/83e21a1df8d8a4eee47f055ee762ec048cc99364) - add `ndarray/base/flatten-shape`
1516
- [`266240f`](https://github.com/stdlib-js/stdlib/commit/266240fa85bf508e01e6583809a1cd49c229a8b2) - add `ndarray/base/binary-input-casting-dtype` [(#7904)](https://github.com/stdlib-js/stdlib/pull/7904)
@@ -508,6 +509,7 @@ A total of 24 issues were closed in this release:
508509

509510
<details>
510511

512+
- [`7944b3f`](https://github.com/stdlib-js/stdlib/commit/7944b3f8ddcaf5f073dd6f304c30d6f385f94d23) - **feat:** add `ndarray/flatten` [(#8021)](https://github.com/stdlib-js/stdlib/pull/8021) _(by Muhammad Haris, Athan Reines)_
511513
- [`4f0bbc6`](https://github.com/stdlib-js/stdlib/commit/4f0bbc61e1be1b422966710f4fd7a4a09e4605a6) - **bench:** remove `const` qualifiers _(by Athan Reines)_
512514
- [`ccbe916`](https://github.com/stdlib-js/stdlib/commit/ccbe91618e58d7955db65dcf29cdcb2651408857) - **fix:** remove stray include _(by Athan Reines)_
513515
- [`11c01f2`](https://github.com/stdlib-js/stdlib/commit/11c01f20be688370014f77248a2f6cf423dfbdc2) - **feat:** add `flattenShape` to namespace _(by Athan Reines)_

flatten/README.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# flatten
22+
23+
> Return a flattened copy of an input [ndarray][@stdlib/ndarray/ctor].
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var flatten = require( '@stdlib/ndarray/flatten' );
37+
```
38+
39+
#### flatten( x\[, options] )
40+
41+
Returns a flattened copy of an input [ndarray][@stdlib/ndarray/ctor].
42+
43+
```javascript
44+
var array = require( '@stdlib/ndarray/array' );
45+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
46+
47+
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] );
48+
// returns <ndarray>
49+
50+
var y = flatten( x );
51+
// returns <ndarray>
52+
53+
var arr = ndarray2array( y );
54+
// returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
55+
```
56+
57+
The function accepts the following arguments:
58+
59+
- **x**: input [ndarray][@stdlib/ndarray/ctor].
60+
- **options**: function options (_optional_).
61+
62+
The function accepts the following options:
63+
64+
- **order**: order in which input [ndarray][@stdlib/ndarray/ctor] elements should be flattened. Must be one of the following:
65+
66+
- `'row-major'`: flatten elements in lexicographic order. For example, given a two-dimensional input [ndarray][@stdlib/ndarray/ctor] (i.e., a matrix), flattening in lexicographic order means flattening the input [ndarray][@stdlib/ndarray/ctor] row-by-row.
67+
- `'column-major'`: flatten elements in colexicographic order. For example, given a two-dimensional input [ndarray][@stdlib/ndarray/ctor] (i.e., a matrix), flattening in colexicographic order means flattening the input [ndarray][@stdlib/ndarray/ctor] column-by-column.
68+
- `'any'`: flatten according to the physical layout of the input [ndarray][@stdlib/ndarray/ctor] data in memory, regardless of the stated [order][@stdlib/ndarray/orders] of the input [ndarray][@stdlib/ndarray/ctor].
69+
- `'same'`: flatten according to the stated [order][@stdlib/ndarray/orders] of the input [ndarray][@stdlib/ndarray/ctor].
70+
71+
Default: `'row-major'`.
72+
73+
- **depth**: maximum number of input [ndarray][@stdlib/ndarray/ctor] dimensions to flatten.
74+
75+
By default, the function flattens all dimensions of the input [ndarray][@stdlib/ndarray/ctor]. To flatten to a desired depth, specify the `depth` option.
76+
77+
```javascript
78+
var array = require( '@stdlib/ndarray/array' );
79+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
80+
81+
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] );
82+
// returns <ndarray>
83+
84+
var y = flatten( x, {
85+
'depth': 1
86+
});
87+
// returns <ndarray>
88+
89+
var arr = ndarray2array( y );
90+
// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
91+
```
92+
93+
By default, the input [ndarray][@stdlib/ndarray/ctor] is flattened in lexicographic order. To flatten elements in a different order, specify the `order` option.
94+
95+
```javascript
96+
var array = require( '@stdlib/ndarray/array' );
97+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
98+
99+
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] );
100+
// returns <ndarray>
101+
102+
var y = flatten( x, {
103+
'order': 'column-major'
104+
});
105+
// returns <ndarray>
106+
107+
var arr = ndarray2array( y );
108+
// returns [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ]
109+
```
110+
111+
</section>
112+
113+
<!-- /.usage -->
114+
115+
<section class="notes">
116+
117+
## Notes
118+
119+
- The function **always** returns a copy of input [ndarray][@stdlib/ndarray/ctor] data, even when an input [ndarray][@stdlib/ndarray/ctor] already has the desired number of dimensions.
120+
121+
</section>
122+
123+
<!-- /.notes -->
124+
125+
<section class="examples">
126+
127+
## Examples
128+
129+
<!-- eslint no-undef: "error" -->
130+
131+
```javascript
132+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
133+
var array = require( '@stdlib/ndarray/array' );
134+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
135+
var flatten = require( '@stdlib/ndarray/flatten' );
136+
137+
var xbuf = discreteUniform( 12, -100, 100, {
138+
'dtype': 'generic'
139+
});
140+
141+
var x = array( xbuf, {
142+
'shape': [ 2, 2, 3 ],
143+
'dtype': 'generic'
144+
});
145+
console.log( ndarray2array( x ) );
146+
147+
var y = flatten( x );
148+
console.log( ndarray2array( y ) );
149+
```
150+
151+
</section>
152+
153+
<!-- /.examples -->
154+
155+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
156+
157+
<section class="related">
158+
159+
</section>
160+
161+
<!-- /.related -->
162+
163+
<section class="links">
164+
165+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
166+
167+
[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray/tree/main/orders
168+
169+
<!-- <related-links> -->
170+
171+
<!-- </related-links> -->
172+
173+
</section>
174+
175+
<!-- /.links -->

0 commit comments

Comments
 (0)