Skip to content

Commit c0ab24d

Browse files
committed
refactor: most of the stuff
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent dcd128d commit c0ab24d

File tree

9 files changed

+842
-115
lines changed

9 files changed

+842
-115
lines changed

lib/node_modules/@stdlib/ndarray/flatten/README.md

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ limitations under the License.
3636
var flatten = require( '@stdlib/ndarray/flatten' );
3737
```
3838

39-
#### flatten( x, depth )
39+
#### flatten( x\[, options] )
4040

4141
Returns a flattened copy of an input [`ndarray`][@stdlib/ndarray/ctor].
4242

@@ -48,7 +48,7 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' );
4848
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] );
4949
// returns <ndarray>
5050

51-
var y = flatten( x, 2 );
51+
var y = flatten( x );
5252
// returns <ndarray>
5353

5454
var arr = ndarray2array( y );
@@ -58,18 +58,63 @@ var arr = ndarray2array( y );
5858
The function accepts the following arguments:
5959

6060
- **x**: input [`ndarray`][@stdlib/ndarray/ctor].
61-
- **depth**: a non-negative integer specifying the number of input [`ndarray`][@stdlib/ndarray/ctor] dimensions to flatten.
61+
- **options**: function options (_optional_).
62+
63+
The function accepts the following options:
64+
65+
- **depth**: a nonnegative integer specifying the number of input [`ndarray`][@stdlib/ndarray/ctor] dimensions to flatten.
66+
67+
- **order**: order of the output [`ndarray`][@stdlib/ndarray/ctor]. The option may be one of the following values:
68+
69+
- `'row-major'`: the input [`ndarray`][@stdlib/ndarray/ctor] is flattened in lexicographic [order][@stdlib/ndarray/orders].
70+
- `'column-major'`: the input [`ndarray`][@stdlib/ndarray/ctor] is flattened in colexicographic [order][@stdlib/ndarray/orders].
71+
- `'any'`: the input [`ndarray`][@stdlib/ndarray/ctor] is flattened in colexicographic [order][@stdlib/ndarray/orders] if the input [`ndarray`][@stdlib/ndarray/ctor] is column-major; otherwise, it is flattened in lexicographic [order][@stdlib/ndarray/orders].
72+
- `'same'`: the input [`ndarray`][@stdlib/ndarray/ctor] is flattened in the [order][@stdlib/ndarray/orders] of the input [`ndarray`][@stdlib/ndarray/ctor].
73+
74+
By default, all the dimensinos of the input [ndarray][@stdlib/ndarray/ctor] are flattened. To flatten upto to a specific `depth`, specify the `depth` option.
75+
76+
```javascript
77+
var array = require( '@stdlib/ndarray/array' );
78+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
79+
80+
// Create an input ndarray:
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 in a different [order][@stdlib/ndarray/orders], specify the `order` option.
94+
95+
```javascript
96+
var array = require( '@stdlib/ndarray/array' );
97+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
98+
99+
// Create an input ndarray:
100+
var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] );
101+
// returns <ndarray>
102+
103+
var y = flatten( x, {
104+
'order': 'column-major'
105+
});
106+
// returns <ndarray>
107+
108+
var arr = ndarray2array( y );
109+
// returns [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ]
110+
```
62111

63112
</section>
64113

65114
<!-- /.usage -->
66115

67116
<section class="notes">
68117

69-
## Notes
70-
71-
- The provided input [`ndarray`][@stdlib/ndarray/ctor] **must** have more than one-dimension.
72-
73118
</section>
74119

75120
<!-- /.notes -->
@@ -98,7 +143,7 @@ var x = array( xbuf, {
98143
console.log( ndarray2array( x ) );
99144

100145
// Flatten the input ndarray:
101-
var y = flatten( x, 2 );
146+
var y = flatten( x );
102147
console.log( ndarray2array( y ) );
103148
```
104149

@@ -118,6 +163,8 @@ console.log( ndarray2array( y ) );
118163

119164
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor
120165

166+
[@stdlib/ndarray/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders
167+
121168
<!-- <related-links> -->
122169

123170
<!-- </related-links> -->

lib/node_modules/@stdlib/ndarray/flatten/benchmark/benchmark.js

Lines changed: 168 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ var flatten = require( './../lib' );
2929

3030
// MAIN //
3131

32-
bench( pkg+'::2d', function benchmark( b ) {
32+
bench( pkg+'::2d:row-major', function benchmark( b ) {
3333
var values;
34+
var opts;
3435
var y;
3536
var i;
3637
var j;
@@ -42,11 +43,15 @@ bench( pkg+'::2d', function benchmark( b ) {
4243
zeros( 'complex128', [ 2, 2 ], 'row-major' ),
4344
zeros( 'generic', [ 2, 2 ], 'row-major' )
4445
];
46+
opts = {
47+
'depth': 1,
48+
'order': 'row-major'
49+
};
4550

4651
b.tic();
4752
for ( i = 0; i < b.iterations; i++ ) {
4853
j = i % values.length;
49-
y = flatten( values[ j ], 1 );
54+
y = flatten( values[ j ], opts );
5055
if ( typeof y !== 'object' ) {
5156
b.fail( 'should return an ndarray' );
5257
}
@@ -59,8 +64,79 @@ bench( pkg+'::2d', function benchmark( b ) {
5964
b.end();
6065
});
6166

62-
bench( pkg+'::3d', function benchmark( b ) {
67+
bench( pkg+'::2d:column-major', function benchmark( b ) {
6368
var values;
69+
var opts;
70+
var y;
71+
var i;
72+
var j;
73+
74+
values = [
75+
zeros( 'float64', [ 2, 2 ], 'row-major' ),
76+
zeros( 'float32', [ 2, 2 ], 'row-major' ),
77+
zeros( 'int32', [ 2, 2 ], 'row-major' ),
78+
zeros( 'complex128', [ 2, 2 ], 'row-major' ),
79+
zeros( 'generic', [ 2, 2 ], 'row-major' )
80+
];
81+
opts = {
82+
'depth': 1,
83+
'order': 'column-major'
84+
};
85+
86+
b.tic();
87+
for ( i = 0; i < b.iterations; i++ ) {
88+
j = i % values.length;
89+
y = flatten( values[ j ], opts );
90+
if ( typeof y !== 'object' ) {
91+
b.fail( 'should return an ndarray' );
92+
}
93+
}
94+
b.toc();
95+
if ( !isndarrayLike( y ) ) {
96+
b.fail( 'should return an ndarray' );
97+
}
98+
b.pass( 'benchmark finished' );
99+
b.end();
100+
});
101+
102+
bench( pkg+'::3d:row-major', function benchmark( b ) {
103+
var values;
104+
var opts;
105+
var y;
106+
var i;
107+
var j;
108+
109+
values = [
110+
zeros( 'float64', [ 2, 2, 2 ], 'row-major' ),
111+
zeros( 'float32', [ 2, 2, 2 ], 'row-major' ),
112+
zeros( 'int32', [ 2, 2, 2 ], 'row-major' ),
113+
zeros( 'complex128', [ 2, 2, 2 ], 'row-major' ),
114+
zeros( 'generic', [ 2, 2, 2 ], 'row-major' )
115+
];
116+
opts = {
117+
'depth': 2,
118+
'order': 'row-major'
119+
};
120+
121+
b.tic();
122+
for ( i = 0; i < b.iterations; i++ ) {
123+
j = i % values.length;
124+
y = flatten( values[ j ], opts );
125+
if ( typeof y !== 'object' ) {
126+
b.fail( 'should return an ndarray' );
127+
}
128+
}
129+
b.toc();
130+
if ( !isndarrayLike( y ) ) {
131+
b.fail( 'should return an ndarray' );
132+
}
133+
b.pass( 'benchmark finished' );
134+
b.end();
135+
});
136+
137+
bench( pkg+'::3d:column-major', function benchmark( b ) {
138+
var values;
139+
var opts;
64140
var y;
65141
var i;
66142
var j;
@@ -72,11 +148,15 @@ bench( pkg+'::3d', function benchmark( b ) {
72148
zeros( 'complex128', [ 2, 2, 2 ], 'row-major' ),
73149
zeros( 'generic', [ 2, 2, 2 ], 'row-major' )
74150
];
151+
opts = {
152+
'depth': 2,
153+
'order': 'column-major'
154+
};
75155

76156
b.tic();
77157
for ( i = 0; i < b.iterations; i++ ) {
78158
j = i % values.length;
79-
y = flatten( values[ j ], 2 );
159+
y = flatten( values[ j ], opts );
80160
if ( typeof y !== 'object' ) {
81161
b.fail( 'should return an ndarray' );
82162
}
@@ -89,8 +169,9 @@ bench( pkg+'::3d', function benchmark( b ) {
89169
b.end();
90170
});
91171

92-
bench( pkg+'::4d', function benchmark( b ) {
172+
bench( pkg+'::4d:row-major', function benchmark( b ) {
93173
var values;
174+
var opts;
94175
var y;
95176
var i;
96177
var j;
@@ -102,11 +183,85 @@ bench( pkg+'::4d', function benchmark( b ) {
102183
zeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ),
103184
zeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' )
104185
];
186+
opts = {
187+
'depth': 3,
188+
'order': 'row-major'
189+
};
190+
191+
b.tic();
192+
for ( i = 0; i < b.iterations; i++ ) {
193+
j = i % values.length;
194+
y = flatten( values[ j ], opts );
195+
if ( typeof y !== 'object' ) {
196+
b.fail( 'should return an ndarray' );
197+
}
198+
}
199+
b.toc();
200+
if ( !isndarrayLike( y ) ) {
201+
b.fail( 'should return an ndarray' );
202+
}
203+
b.pass( 'benchmark finished' );
204+
b.end();
205+
});
206+
207+
bench( pkg+'::4d:column-major', function benchmark( b ) {
208+
var values;
209+
var opts;
210+
var y;
211+
var i;
212+
var j;
213+
214+
values = [
215+
zeros( 'float64', [ 2, 2, 2, 2 ], 'row-major' ),
216+
zeros( 'float32', [ 2, 2, 2, 2 ], 'row-major' ),
217+
zeros( 'int32', [ 2, 2, 2, 2 ], 'row-major' ),
218+
zeros( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ),
219+
zeros( 'generic', [ 2, 2, 2, 2 ], 'row-major' )
220+
];
221+
opts = {
222+
'depth': 3,
223+
'order': 'column-major'
224+
};
225+
226+
b.tic();
227+
for ( i = 0; i < b.iterations; i++ ) {
228+
j = i % values.length;
229+
y = flatten( values[ j ], opts );
230+
if ( typeof y !== 'object' ) {
231+
b.fail( 'should return an ndarray' );
232+
}
233+
}
234+
b.toc();
235+
if ( !isndarrayLike( y ) ) {
236+
b.fail( 'should return an ndarray' );
237+
}
238+
b.pass( 'benchmark finished' );
239+
b.end();
240+
});
241+
242+
bench( pkg+'::5d:row-major', function benchmark( b ) {
243+
var values;
244+
var opts;
245+
var y;
246+
var i;
247+
var j;
248+
249+
values = [
250+
zeros( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ),
251+
zeros( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ),
252+
zeros( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ),
253+
zeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ),
254+
zeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' )
255+
];
256+
opts = {
257+
'depth': 4,
258+
'order': 'row-major'
259+
};
105260

106261
b.tic();
107262
for ( i = 0; i < b.iterations; i++ ) {
108263
j = i % values.length;
109-
y = flatten( values[ j ], 3 );
264+
y = flatten( values[ j ], opts );
110265
if ( typeof y !== 'object' ) {
111266
b.fail( 'should return an ndarray' );
112267
}
@@ -119,8 +274,9 @@ bench( pkg+'::4d', function benchmark( b ) {
119274
b.end();
120275
});
121276

122-
bench( pkg+'::5d', function benchmark( b ) {
277+
bench( pkg+'::5d:column-major', function benchmark( b ) {
123278
var values;
279+
var opts;
124280
var y;
125281
var i;
126282
var j;
@@ -132,11 +288,15 @@ bench( pkg+'::5d', function benchmark( b ) {
132288
zeros( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ),
133289
zeros( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' )
134290
];
291+
opts = {
292+
'depth': 4,
293+
'order': 'column-major'
294+
};
135295

136296
b.tic();
137297
for ( i = 0; i < b.iterations; i++ ) {
138298
j = i % values.length;
139-
y = flatten( values[ j ], 4 );
299+
y = flatten( values[ j ], opts );
140300
if ( typeof y !== 'object' ) {
141301
b.fail( 'should return an ndarray' );
142302
}

lib/node_modules/@stdlib/ndarray/flatten/docs/repl.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11

2-
{{alias}}( x, depth )
2+
{{alias}}( x[, options] )
33
Returns a flattened copy of an input ndarray.
44

5-
The `depth` must be a valid non-negative integer.
6-
75
Parameters
86
----------
97
x: ndarray
108
Input ndarray.
119

12-
depth: integer
13-
A non-negative integer specifying the number of input ndarray dimensions
14-
to flatten.
10+
options: Object (optional)
11+
Function options.
12+
13+
options.depth: integer (optional)
14+
Number of dimensions to flatten.
15+
16+
options.order: string (optional)
17+
Order of the output ndarray.
1518

1619
Returns
1720
-------
@@ -21,10 +24,9 @@
2124
Examples
2225
--------
2326
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
24-
> var y = {{alias}}( x, 1 );
27+
> var y = {{alias}}( x );
2528
> var arr = {{alias:@stdlib/ndarray/to-array}}( y )
2629
[ 1.0, 2.0, 3.0, 4.0 ]
2730

2831
See Also
2932
--------
30-

0 commit comments

Comments
 (0)