@stdlib/array-base-flatten5d 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2023 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,244 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2023 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
+ # flatten5d
22
+
23
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
24
+
25
+ > Flatten a five-dimensional nested array.
26
+
27
+ <section class="installation">
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ npm install @stdlib/array-base-flatten5d
33
+ ```
34
+
35
+ </section>
36
+
37
+ <section class="usage">
38
+
39
+ ## Usage
40
+
41
+ ```javascript
42
+ var flatten5d = require( '@stdlib/array-base-flatten5d' );
43
+ ```
44
+
45
+ #### flatten5d( x, shape, colexicographic )
46
+
47
+ Flattens a five-dimensional nested array.
48
+
49
+ ```javascript
50
+ var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
51
+
52
+ var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], false );
53
+ // returns [ 1, 2, 3, 4 ]
54
+ ```
55
+
56
+ To flatten in colexicographic order, provide a third argument equal to `true`.
57
+
58
+ ```javascript
59
+ var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
60
+
61
+ var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], true );
62
+ // returns [ 1, 3, 2, 4 ]
63
+ ```
64
+
65
+ #### flatten5d.assign( x, shape, colexicographic, out, stride, offset )
66
+
67
+ Flattens a five-dimensional nested array and assigns elements to a provided output array.
68
+
69
+ ```javascript
70
+ var Float64Array = require( '@stdlib/array-float64' );
71
+
72
+ var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
73
+ var out = new Float64Array( 4 );
74
+
75
+ var y = flatten5d.assign( x, [ 2, 1, 1, 1, 2 ], false, out, 1, 0 );
76
+ // returns <Float64Array>[ 1, 2, 3, 4 ]
77
+
78
+ var bool = ( y === out );
79
+ // returns true
80
+
81
+ y = flatten5d.assign( x, [ 2, 1, 1, 1, 2 ], true, out, 1, 0 );
82
+ // returns <Float64Array>[ 1, 3, 2, 4 ]
83
+ ```
84
+
85
+ </section>
86
+
87
+ <!-- /.usage -->
88
+
89
+ <section class="notes">
90
+
91
+ ## Notes
92
+
93
+ - Both functions assume that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
94
+
95
+ </section>
96
+
97
+ <!-- /.notes -->
98
+
99
+ <section class="examples">
100
+
101
+ ## Examples
102
+
103
+ <!-- eslint no-undef: "error" -->
104
+
105
+ ```javascript
106
+ var flatten5d = require( '@stdlib/array-base-flatten5d' );
107
+
108
+ // Define a 2x2x1x2x2 array:
109
+ var x = [
110
+ [
111
+ [
112
+ [
113
+ [ 1, 2 ], [ 3, 4 ]
114
+ ]
115
+ ],
116
+ [
117
+ [
118
+ [ 5, 6 ], [ 7, 8 ]
119
+ ]
120
+ ]
121
+ ],
122
+ [
123
+ [
124
+ [
125
+ [ 9, 10 ], [ 11, 12 ]
126
+ ]
127
+ ],
128
+ [
129
+ [
130
+ [ 13, 14 ], [ 15, 16 ]
131
+ ]
132
+ ]
133
+ ]
134
+ ];
135
+
136
+ var out = flatten5d( x, [ 0, 0, 0, 0, 0 ], false );
137
+ // returns []
138
+
139
+ out = flatten5d( x, [ 0, 0, 0, 0, 0 ], true );
140
+ // returns []
141
+
142
+ out = flatten5d( x, [ 1, 1, 1, 1, 1 ], false );
143
+ // returns [ 1 ]
144
+
145
+ out = flatten5d( x, [ 1, 1, 1, 1, 1 ], true );
146
+ // returns [ 1 ]
147
+
148
+ out = flatten5d( x, [ 1, 2, 1, 2, 2 ], false );
149
+ // returns [ 1, 2, 3, 4, 5, 6, 7, 8 ]
150
+
151
+ out = flatten5d( x, [ 1, 2, 1, 2, 2 ], true );
152
+ // returns [ 1, 5, 3, 7, 2, 6, 4, 8 ]
153
+
154
+ out = flatten5d( x, [ 2, 2, 1, 2, 2 ], false );
155
+ // returns [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
156
+
157
+ out = flatten5d( x, [ 2, 2, 1, 2, 2 ], true );
158
+ // returns [ 1, 9, 5, 13, 3, 11, 7, 15, 2, 10, 6, 14, 4, 12, 8, 16 ]
159
+ ```
160
+
161
+ </section>
162
+
163
+ <!-- /.examples -->
164
+
165
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
166
+
167
+ <section class="related">
168
+
169
+ </section>
170
+
171
+ <!-- /.related -->
172
+
173
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
174
+
175
+
176
+ <section class="main-repo" >
177
+
178
+ * * *
179
+
180
+ ## Notice
181
+
182
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
183
+
184
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
185
+
186
+ #### Community
187
+
188
+ [![Chat][chat-image]][chat-url]
189
+
190
+ ---
191
+
192
+ ## License
193
+
194
+ See [LICENSE][stdlib-license].
195
+
196
+
197
+ ## Copyright
198
+
199
+ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
200
+
201
+ </section>
202
+
203
+ <!-- /.stdlib -->
204
+
205
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
206
+
207
+ <section class="links">
208
+
209
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/array-base-flatten5d.svg
210
+ [npm-url]: https://npmjs.org/package/@stdlib/array-base-flatten5d
211
+
212
+ [test-image]: https://github.com/stdlib-js/array-base-flatten5d/actions/workflows/test.yml/badge.svg?branch=v0.0.1
213
+ [test-url]: https://github.com/stdlib-js/array-base-flatten5d/actions/workflows/test.yml?query=branch:v0.0.1
214
+
215
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-flatten5d/main.svg
216
+ [coverage-url]: https://codecov.io/github/stdlib-js/array-base-flatten5d?branch=main
217
+
218
+ <!--
219
+
220
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/array-base-flatten5d.svg
221
+ [dependencies-url]: https://david-dm.org/stdlib-js/array-base-flatten5d/main
222
+
223
+ -->
224
+
225
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
226
+ [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
227
+
228
+ [stdlib]: https://github.com/stdlib-js/stdlib
229
+
230
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
231
+
232
+ [umd]: https://github.com/umdjs/umd
233
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
234
+
235
+ [deno-url]: https://github.com/stdlib-js/array-base-flatten5d/tree/deno
236
+ [umd-url]: https://github.com/stdlib-js/array-base-flatten5d/tree/umd
237
+ [esm-url]: https://github.com/stdlib-js/array-base-flatten5d/tree/esm
238
+ [branches-url]: https://github.com/stdlib-js/array-base-flatten5d/blob/main/branches.md
239
+
240
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-flatten5d/main/LICENSE
241
+
242
+ </section>
243
+
244
+ <!-- /.links -->
@@ -0,0 +1,123 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ // TypeScript Version: 4.1
20
+
21
+ /// <reference types="@stdlib/types"/>
22
+
23
+ import { Collection } from '@stdlib/types/object';
24
+
25
+ /**
26
+ * Five-dimensional nested array.
27
+ */
28
+ type Array5D<T> = Array<Array<Array<Array<Collection<T>>>>>;
29
+
30
+ /**
31
+ * Interface describing `flatten5d`.
32
+ */
33
+ interface Flatten5d {
34
+ /**
35
+ * Flattens a five-dimensional nested array.
36
+ *
37
+ * ## Notes
38
+ *
39
+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
40
+ *
41
+ * @param x - input array
42
+ * @param shape - array shape
43
+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
44
+ * @returns flattened array
45
+ *
46
+ * @example
47
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
48
+ *
49
+ * var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], false );
50
+ * // returns [ 1, 2, 3, 4 ]
51
+ *
52
+ * @example
53
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
54
+ *
55
+ * var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], true );
56
+ * // returns [ 1, 3, 2, 4 ]
57
+ */
58
+ <T = unknown>( x: Array5D<T>, shape: Collection<number>, colexicographic: boolean ): Array<T>;
59
+
60
+ /**
61
+ * Flattens a five-dimensional nested array and assigns elements to a provided output array.
62
+ *
63
+ * ## Notes
64
+ *
65
+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
66
+ *
67
+ * @param x - input array
68
+ * @param shape - array shape
69
+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
70
+ * @param out - output array
71
+ * @param stride - output array stride
72
+ * @param offset - output array index offset
73
+ * @returns output array
74
+ *
75
+ * @example
76
+ * var Float64Array = require( `@stdlib/array/float64` );
77
+ *
78
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
79
+ *
80
+ * var out = flatten5d.assign( x, [ 2, 2 ], false, new Float64Array( 4 ), 1, 0 );
81
+ * // returns <Float64Array>[ 1, 2, 3, 4 ]
82
+ *
83
+ * @example
84
+ * var Float64Array = require( `@stdlib/array/float64` );
85
+ *
86
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
87
+ *
88
+ * var out = flatten5d.assign( x, [ 2, 2 ], true, new Float64Array( 4 ), 1, 0 );
89
+ * // returns <Float64Array>[ 1, 3, 2, 4 ]
90
+ */
91
+ assign<T = unknown, U = unknown>( x: Array5D<T>, shape: Collection<number>, colexicographic: boolean, out: Collection<U>, stride: number, offset: number ): Collection<T | U>;
92
+ }
93
+
94
+ /**
95
+ * Flattens a five-dimensional nested array.
96
+ *
97
+ * ## Notes
98
+ *
99
+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
100
+ *
101
+ * @param x - input array
102
+ * @param shape - array shape
103
+ * @param colexicographic - specifies whether to flatten array values in colexicographic order
104
+ * @returns flattened array
105
+ *
106
+ * @example
107
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
108
+ *
109
+ * var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], false );
110
+ * // returns [ 1, 2, 3, 4 ]
111
+ *
112
+ * @example
113
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
114
+ *
115
+ * var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], true );
116
+ * // returns [ 1, 3, 2, 4 ]
117
+ */
118
+ declare var flatten5d: Flatten5d;
119
+
120
+
121
+ // EXPORTS //
122
+
123
+ export = flatten5d;
package/lib/assign.js ADDED
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ /* eslint-disable max-depth */
20
+
21
+ 'use strict';
22
+
23
+ // MAIN //
24
+
25
+ /**
26
+ * Flattens a five-dimensional nested array and assigns elements to a provided output array.
27
+ *
28
+ * ## Notes
29
+ *
30
+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
31
+ *
32
+ * @param {Array<Array<Collection>>} x - input nested array
33
+ * @param {NonNegativeIntegerArray} shape - array shape
34
+ * @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order
35
+ * @param {Collection} out - output array
36
+ * @param {integer} stride - output array stride
37
+ * @param {NonNegativeInteger} offset - output array index offset
38
+ * @returns {Collection} output array
39
+ *
40
+ * @example
41
+ * var Float64Array = require( '@stdlib/array-float64' );
42
+ *
43
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
44
+ *
45
+ * var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], false, new Float64Array( 4 ), 1, 0 );
46
+ * // returns <Float64Array>[ 1, 2, 3, 4 ]
47
+ *
48
+ * @example
49
+ * var Float64Array = require( '@stdlib/array-float64' );
50
+ *
51
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
52
+ *
53
+ * var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], true, new Float64Array( 4 ), 1, 0 );
54
+ * // returns <Float64Array>[ 1, 3, 2, 4 ]
55
+ */
56
+ function flatten5d( x, shape, colexicographic, out, stride, offset ) {
57
+ var S0;
58
+ var S1;
59
+ var S2;
60
+ var S3;
61
+ var S4;
62
+ var i0;
63
+ var i1;
64
+ var i2;
65
+ var i3;
66
+ var i4;
67
+ var a0;
68
+ var a1;
69
+ var a2;
70
+ var a3;
71
+ var io;
72
+
73
+ // Extract loop variables:
74
+ S0 = shape[ 4 ]; // for nested arrays, the last dimensions have the fastest changing indices
75
+ S1 = shape[ 3 ];
76
+ S2 = shape[ 2 ];
77
+ S3 = shape[ 1 ];
78
+ S4 = shape[ 0 ];
79
+
80
+ // Iterate over the array dimensions...
81
+ io = offset;
82
+ if ( colexicographic ) {
83
+ for ( i0 = 0; i0 < S0; i0++ ) {
84
+ for ( i1 = 0; i1 < S1; i1++ ) {
85
+ for ( i2 = 0; i2 < S2; i2++ ) {
86
+ for ( i3 = 0; i3 < S3; i3++ ) {
87
+ for ( i4 = 0; i4 < S4; i4++ ) {
88
+ out[ io ] = x[ i4 ][ i3 ][ i2 ][ i1 ][ i0 ]; // equivalent to storing in column-major (Fortran-style) order
89
+ io += stride;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ return out;
96
+ }
97
+ for ( i4 = 0; i4 < S4; i4++ ) {
98
+ a3 = x[ i4 ];
99
+ for ( i3 = 0; i3 < S3; i3++ ) {
100
+ a2 = a3[ i3 ];
101
+ for ( i2 = 0; i2 < S2; i2++ ) {
102
+ a1 = a2[ i2 ];
103
+ for ( i1 = 0; i1 < S1; i1++ ) {
104
+ a0 = a1[ i1 ];
105
+ for ( i0 = 0; i0 < S0; i0++ ) {
106
+ out[ io ] = a0[ i0 ]; // equivalent to storing in row-major (C-style) order
107
+ io += stride;
108
+ }
109
+ }
110
+ }
111
+ }
112
+ }
113
+ return out;
114
+ }
115
+
116
+
117
+ // EXPORTS //
118
+
119
+ module.exports = flatten5d;
package/lib/index.js ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Flatten a five-dimensional nested array.
23
+ *
24
+ * @module @stdlib/array-base-flatten5d
25
+ *
26
+ * @example
27
+ * var flatten5d = require( '@stdlib/array-base-flatten5d' );
28
+ *
29
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
30
+ *
31
+ * var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], false );
32
+ * // returns [ 1, 2, 3, 4 ]
33
+ *
34
+ * @example
35
+ * var flatten5d = require( '@stdlib/array-base-flatten5d' );
36
+ *
37
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
38
+ *
39
+ * var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], true );
40
+ * // returns [ 1, 3, 2, 4 ]
41
+ *
42
+ * @example
43
+ * var Float64Array = require( '@stdlib/array-float64' );
44
+ * var flatten5d = require( '@stdlib/array-base-flatten5d' );
45
+ *
46
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
47
+ *
48
+ * var out = new Float64Array( 4 );
49
+ * var y = flatten5d.assign( x, [ 2, 1, 1, 1, 2 ], true, out, 1, 0 );
50
+ * // returns <Float64Array>[ 1, 3, 2, 4 ]
51
+ *
52
+ * var bool = ( y === out );
53
+ * // returns true
54
+ */
55
+
56
+ // MODULES //
57
+
58
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
59
+ var main = require( './main.js' );
60
+ var assign = require( './assign.js' );
61
+
62
+
63
+ // MAIN //
64
+
65
+ setReadOnly( main, 'assign', assign );
66
+
67
+
68
+ // EXPORTS //
69
+
70
+ module.exports = main;
package/lib/main.js ADDED
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2023 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ /* eslint-disable max-depth */
20
+
21
+ 'use strict';
22
+
23
+ // MAIN //
24
+
25
+ /**
26
+ * Flattens a five-dimensional nested array.
27
+ *
28
+ * ## Notes
29
+ *
30
+ * - The function assumes that all nested arrays have the same length (i.e., the input array is **not** a ragged array).
31
+ *
32
+ * @param {Array<Array<Collection>>} x - input nested array
33
+ * @param {NonNegativeIntegerArray} shape - array shape
34
+ * @param {boolean} colexicographic - specifies whether to flatten array values in colexicographic order
35
+ * @returns {Array} flattened array
36
+ *
37
+ * @example
38
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
39
+ *
40
+ * var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], false );
41
+ * // returns [ 1, 2, 3, 4 ]
42
+ *
43
+ * @example
44
+ * var x = [ [ [ [ [ 1, 2 ] ] ] ], [ [ [ [ 3, 4 ] ] ] ] ];
45
+ *
46
+ * var out = flatten5d( x, [ 2, 1, 1, 1, 2 ], true );
47
+ * // returns [ 1, 3, 2, 4 ]
48
+ */
49
+ function flatten5d( x, shape, colexicographic ) {
50
+ var out;
51
+ var S0;
52
+ var S1;
53
+ var S2;
54
+ var S3;
55
+ var S4;
56
+ var i0;
57
+ var i1;
58
+ var i2;
59
+ var i3;
60
+ var i4;
61
+ var a0;
62
+ var a1;
63
+ var a2;
64
+ var a3;
65
+
66
+ // Extract loop variables:
67
+ S0 = shape[ 4 ]; // for nested arrays, the last dimensions have the fastest changing indices
68
+ S1 = shape[ 3 ];
69
+ S2 = shape[ 2 ];
70
+ S3 = shape[ 1 ];
71
+ S4 = shape[ 0 ];
72
+
73
+ // Initialize an output array:
74
+ out = [];
75
+
76
+ // Iterate over the array dimensions...
77
+ if ( colexicographic ) {
78
+ for ( i0 = 0; i0 < S0; i0++ ) {
79
+ for ( i1 = 0; i1 < S1; i1++ ) {
80
+ for ( i2 = 0; i2 < S2; i2++ ) {
81
+ for ( i3 = 0; i3 < S3; i3++ ) {
82
+ for ( i4 = 0; i4 < S4; i4++ ) {
83
+ out.push( x[ i4 ][ i3 ][ i2 ][ i1 ][ i0 ] ); // equivalent to storing in column-major (Fortran-style) order
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ return out;
90
+ }
91
+ for ( i4 = 0; i4 < S4; i4++ ) {
92
+ a3 = x[ i4 ];
93
+ for ( i3 = 0; i3 < S3; i3++ ) {
94
+ a2 = a3[ i3 ];
95
+ for ( i2 = 0; i2 < S2; i2++ ) {
96
+ a1 = a2[ i2 ];
97
+ for ( i1 = 0; i1 < S1; i1++ ) {
98
+ a0 = a1[ i1 ];
99
+ for ( i0 = 0; i0 < S0; i0++ ) {
100
+ out.push( a0[ i0 ] ); // equivalent to storing in row-major (C-style) order
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ return out;
107
+ }
108
+
109
+
110
+ // EXPORTS //
111
+
112
+ module.exports = flatten5d;
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@stdlib/array-base-flatten5d",
3
+ "version": "0.0.1",
4
+ "description": "Flatten a five-dimensional nested array.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "benchmark": "./benchmark",
19
+ "doc": "./docs",
20
+ "example": "./examples",
21
+ "lib": "./lib",
22
+ "test": "./test"
23
+ },
24
+ "types": "./docs/types",
25
+ "scripts": {
26
+ "test": "make test",
27
+ "test-cov": "make test-cov",
28
+ "examples": "make examples",
29
+ "benchmark": "make benchmark"
30
+ },
31
+ "homepage": "https://stdlib.io",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git://github.com/stdlib-js/array-base-flatten5d.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/stdlib-js/stdlib/issues"
38
+ },
39
+ "dependencies": {
40
+ "@stdlib/types": "^0.0.14",
41
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7"
42
+ },
43
+ "devDependencies": {
44
+ "@stdlib/array-base-filled": "^0.0.2",
45
+ "@stdlib/array-base-zero-to": "^0.0.6",
46
+ "@stdlib/array-float64": "^0.0.6",
47
+ "@stdlib/assert-has-own-property": "^0.0.7",
48
+ "@stdlib/assert-is-array": "^0.0.7",
49
+ "@stdlib/assert-is-float64array": "^0.0.8",
50
+ "@stdlib/bench": "^0.0.12",
51
+ "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
52
+ "istanbul": "^0.4.1",
53
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
54
+ },
55
+ "engines": {
56
+ "node": ">=0.10.0",
57
+ "npm": ">2.7.0"
58
+ },
59
+ "os": [
60
+ "aix",
61
+ "darwin",
62
+ "freebsd",
63
+ "linux",
64
+ "macos",
65
+ "openbsd",
66
+ "sunos",
67
+ "win32",
68
+ "windows"
69
+ ],
70
+ "keywords": [
71
+ "stdlib",
72
+ "utilities",
73
+ "utils",
74
+ "generic",
75
+ "array",
76
+ "flatten",
77
+ "flat",
78
+ "5d",
79
+ "tensor",
80
+ "strided",
81
+ "ndarray",
82
+ "multidimensional"
83
+ ],
84
+ "funding": {
85
+ "type": "opencollective",
86
+ "url": "https://opencollective.com/stdlib"
87
+ }
88
+ }