@stdlib/array-base-map5d 0.1.0
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 +177 -0
- package/NOTICE +1 -0
- package/README.md +254 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +186 -0
- package/lib/assign.js +109 -0
- package/lib/index.js +75 -0
- package/lib/main.js +101 -0
- package/package.json +94 -0
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,254 @@
|
|
|
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
|
+
|
|
22
|
+
<details>
|
|
23
|
+
<summary>
|
|
24
|
+
About stdlib...
|
|
25
|
+
</summary>
|
|
26
|
+
<p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
|
|
27
|
+
<p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
|
|
28
|
+
<p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
|
|
29
|
+
<p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
|
|
30
|
+
</details>
|
|
31
|
+
|
|
32
|
+
# map5d
|
|
33
|
+
|
|
34
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
35
|
+
|
|
36
|
+
> Apply a function to elements in a five-dimensional nested input array and assign results to elements in a new five-dimensional nested output array.
|
|
37
|
+
|
|
38
|
+
<section class="intro">
|
|
39
|
+
|
|
40
|
+
</section>
|
|
41
|
+
|
|
42
|
+
<!-- /.intro -->
|
|
43
|
+
|
|
44
|
+
<section class="installation">
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install @stdlib/array-base-map5d
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
</section>
|
|
53
|
+
|
|
54
|
+
<section class="usage">
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
var map5d = require( '@stdlib/array-base-map5d' );
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### map5d( x, shape, fcn\[, thisArg] )
|
|
63
|
+
|
|
64
|
+
Applies a function to elements in a five-dimensional nested input array and assigns results to elements in a new five-dimensional nested output array.
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
68
|
+
var abs = require( '@stdlib/math-base-special-abs' );
|
|
69
|
+
|
|
70
|
+
var x = [ [ [ [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] ] ] ];
|
|
71
|
+
var shape = [ 1, 1, 1, 2, 2 ];
|
|
72
|
+
|
|
73
|
+
var y = map5d( x, shape, naryFunction( abs, 1 ) );
|
|
74
|
+
// returns [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The function accepts the following arguments:
|
|
78
|
+
|
|
79
|
+
- **x**: input nested array.
|
|
80
|
+
- **shape**: array shape.
|
|
81
|
+
- **fcn**: function to apply.
|
|
82
|
+
- **thisArg**: applied function execution context (_optional_).
|
|
83
|
+
|
|
84
|
+
To set the applied function's execution context, provide a `thisArg`.
|
|
85
|
+
|
|
86
|
+
<!-- eslint-disable no-invalid-this -->
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
function fcn( x ) {
|
|
90
|
+
this.count += 1;
|
|
91
|
+
return x;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var x = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ];
|
|
95
|
+
var shape = [ 1, 1, 1, 2, 2 ];
|
|
96
|
+
|
|
97
|
+
var ctx = {
|
|
98
|
+
'count': 0
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
var y = map5d( x, shape, fcn, ctx );
|
|
102
|
+
// returns [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]
|
|
103
|
+
|
|
104
|
+
var v = ctx.count;
|
|
105
|
+
// returns 4
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### map5d.assign( x, y, shape, fcn\[, thisArg] )
|
|
109
|
+
|
|
110
|
+
Applies a function to elements in a five-dimensional nested input array and assigns results to elements in a five-dimensional nested output array.
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
114
|
+
var zeros5d = require( '@stdlib/array-base-zeros5d' );
|
|
115
|
+
var abs = require( '@stdlib/math-base-special-abs' );
|
|
116
|
+
|
|
117
|
+
var x = [ [ [ [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] ] ] ];
|
|
118
|
+
var shape = [ 1, 1, 1, 2, 2 ];
|
|
119
|
+
|
|
120
|
+
var y = zeros5d( shape );
|
|
121
|
+
|
|
122
|
+
var out = map5d.assign( x, y, shape, naryFunction( abs, 1 ) );
|
|
123
|
+
// returns [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]
|
|
124
|
+
|
|
125
|
+
var bool = ( out === y );
|
|
126
|
+
// returns true
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The function accepts the following arguments:
|
|
130
|
+
|
|
131
|
+
- **x**: input nested array.
|
|
132
|
+
- **y**: output nested array.
|
|
133
|
+
- **shape**: array shape.
|
|
134
|
+
- **fcn**: function to apply.
|
|
135
|
+
- **thisArg**: applied function execution context (_optional_).
|
|
136
|
+
|
|
137
|
+
The function assumes that the input and output arrays have the same shape.
|
|
138
|
+
|
|
139
|
+
</section>
|
|
140
|
+
|
|
141
|
+
<!-- /.usage -->
|
|
142
|
+
|
|
143
|
+
<section class="notes">
|
|
144
|
+
|
|
145
|
+
</section>
|
|
146
|
+
|
|
147
|
+
<!-- /.notes -->
|
|
148
|
+
|
|
149
|
+
<section class="examples">
|
|
150
|
+
|
|
151
|
+
## Examples
|
|
152
|
+
|
|
153
|
+
<!-- eslint no-undef: "error" -->
|
|
154
|
+
|
|
155
|
+
```javascript
|
|
156
|
+
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory;
|
|
157
|
+
var filled5dBy = require( '@stdlib/array-base-filled5d-by' );
|
|
158
|
+
var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
159
|
+
var abs = require( '@stdlib/math-base-special-abs' );
|
|
160
|
+
var map5d = require( '@stdlib/array-base-map5d' );
|
|
161
|
+
|
|
162
|
+
var shape = [ 1, 1, 3, 3, 3 ];
|
|
163
|
+
|
|
164
|
+
var x = filled5dBy( shape, discreteUniform( -100, 100 ) );
|
|
165
|
+
console.log( x );
|
|
166
|
+
|
|
167
|
+
var y = map5d( x, shape, naryFunction( abs, 1 ) );
|
|
168
|
+
console.log( y );
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
</section>
|
|
172
|
+
|
|
173
|
+
<!-- /.examples -->
|
|
174
|
+
|
|
175
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
176
|
+
|
|
177
|
+
<section class="related">
|
|
178
|
+
|
|
179
|
+
</section>
|
|
180
|
+
|
|
181
|
+
<!-- /.related -->
|
|
182
|
+
|
|
183
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
<section class="main-repo" >
|
|
187
|
+
|
|
188
|
+
* * *
|
|
189
|
+
|
|
190
|
+
## Notice
|
|
191
|
+
|
|
192
|
+
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.
|
|
193
|
+
|
|
194
|
+
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].
|
|
195
|
+
|
|
196
|
+
#### Community
|
|
197
|
+
|
|
198
|
+
[![Chat][chat-image]][chat-url]
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
See [LICENSE][stdlib-license].
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
## Copyright
|
|
208
|
+
|
|
209
|
+
Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
210
|
+
|
|
211
|
+
</section>
|
|
212
|
+
|
|
213
|
+
<!-- /.stdlib -->
|
|
214
|
+
|
|
215
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
216
|
+
|
|
217
|
+
<section class="links">
|
|
218
|
+
|
|
219
|
+
[npm-image]: http://img.shields.io/npm/v/@stdlib/array-base-map5d.svg
|
|
220
|
+
[npm-url]: https://npmjs.org/package/@stdlib/array-base-map5d
|
|
221
|
+
|
|
222
|
+
[test-image]: https://github.com/stdlib-js/array-base-map5d/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
223
|
+
[test-url]: https://github.com/stdlib-js/array-base-map5d/actions/workflows/test.yml?query=branch:v0.1.0
|
|
224
|
+
|
|
225
|
+
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-map5d/main.svg
|
|
226
|
+
[coverage-url]: https://codecov.io/github/stdlib-js/array-base-map5d?branch=main
|
|
227
|
+
|
|
228
|
+
<!--
|
|
229
|
+
|
|
230
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/array-base-map5d.svg
|
|
231
|
+
[dependencies-url]: https://david-dm.org/stdlib-js/array-base-map5d/main
|
|
232
|
+
|
|
233
|
+
-->
|
|
234
|
+
|
|
235
|
+
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
236
|
+
[chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
|
|
237
|
+
|
|
238
|
+
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
239
|
+
|
|
240
|
+
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
241
|
+
|
|
242
|
+
[umd]: https://github.com/umdjs/umd
|
|
243
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
244
|
+
|
|
245
|
+
[deno-url]: https://github.com/stdlib-js/array-base-map5d/tree/deno
|
|
246
|
+
[umd-url]: https://github.com/stdlib-js/array-base-map5d/tree/umd
|
|
247
|
+
[esm-url]: https://github.com/stdlib-js/array-base-map5d/tree/esm
|
|
248
|
+
[branches-url]: https://github.com/stdlib-js/array-base-map5d/blob/main/branches.md
|
|
249
|
+
|
|
250
|
+
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-map5d/main/LICENSE
|
|
251
|
+
|
|
252
|
+
</section>
|
|
253
|
+
|
|
254
|
+
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";var b=function(f,r){return function(){return r||f((r={exports:{}}).exports,r),r.exports}};var k=b(function(G,j){
|
|
2
|
+
function B(f,r,n,R){var O,s,S,e,x,o,a,v,i,u,t,y,q,c,g,l,p,d,m;for(O=r[4],s=r[3],S=r[2],e=r[1],x=r[0],m=[],u=0;u<x;u++){for(p=f[u],d=[],i=0;i<e;i++){for(g=p[i],l=[],v=0;v<S;v++){for(q=g[v],c=[],a=0;a<s;a++){for(t=q[a],y=[],o=0;o<O;o++)y.push(n.call(R,t[o],[u,i,v,a,o],f));c.push(y)}l.push(c)}d.push(l)}m.push(d)}return m}j.exports=B
|
|
3
|
+
});var z=b(function(H,w){
|
|
4
|
+
function C(f,r,n,R,O){var s,S,e,x,o,a,v,i,u,t,y,q,c,g,l,p,d,m;if(s=n[4],S=n[3],e=n[2],x=n[1],o=n[0],s<=0||S<=0||e<=0||x<=0||o<=0)return r;for(t=0;t<o;t++)for(d=f[t],m=r[t],u=0;u<x;u++)for(l=d[u],p=m[u],i=0;i<e;i++)for(c=l[i],g=p[i],v=0;v<S;v++)for(y=c[v],q=g[v],a=0;a<s;a++)q[a]=R.call(O,y[a],[t,u,i,v,a],f);return r}w.exports=C
|
|
5
|
+
});var D=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),A=k(),E=z();D(A,"assign",E);module.exports=A;
|
|
6
|
+
/** @license Apache-2.0 */
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/main.js", "../lib/assign.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Applies a function to elements in a five-dimensional nested input array and assigns results to elements in a new five-dimensional nested output array.\n*\n* @param {ArrayLikeObject<Collection>} x - input nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Function} fcn - function to apply\n* @param {*} [thisArg] - function execution context\n* @returns {Array<Array>} output array\n*\n* @example\n* var ones5d = require( '@stdlib/array-base-ones5d' );\n*\n* function scale( x ) {\n* return x * 10.0;\n* }\n*\n* var shape = [ 1, 1, 1, 2, 2 ];\n*\n* var x = ones5d( shape );\n* var y = map5d( x, shape, scale );\n* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]\n*/\nfunction map5d( x, shape, fcn, thisArg ) {\n\tvar S0;\n\tvar S1;\n\tvar S2;\n\tvar S3;\n\tvar S4;\n\tvar i0;\n\tvar i1;\n\tvar i2;\n\tvar i3;\n\tvar i4;\n\tvar x0;\n\tvar y0;\n\tvar x1;\n\tvar y1;\n\tvar x2;\n\tvar y2;\n\tvar x3;\n\tvar y3;\n\tvar y;\n\n\tS0 = shape[ 4 ];\n\tS1 = shape[ 3 ];\n\tS2 = shape[ 2 ];\n\tS3 = shape[ 1 ];\n\tS4 = shape[ 0 ];\n\ty = [];\n\tfor ( i4 = 0; i4 < S4; i4++ ) {\n\t\tx3 = x[ i4 ];\n\t\ty3 = [];\n\t\tfor ( i3 = 0; i3 < S3; i3++ ) {\n\t\t\tx2 = x3[ i3 ];\n\t\t\ty2 = [];\n\t\t\tfor ( i2 = 0; i2 < S2; i2++ ) {\n\t\t\t\tx1 = x2[ i2 ];\n\t\t\t\ty1 = [];\n\t\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\t\tx0 = x1[ i1 ];\n\t\t\t\t\ty0 = [];\n\t\t\t\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\t\t\t\ty0.push( fcn.call( thisArg, x0[ i0 ], [ i4, i3, i2, i1, i0 ], x ) ); // eslint-disable-line max-len\n\t\t\t\t\t}\n\t\t\t\t\ty1.push( y0 );\n\t\t\t\t}\n\t\t\t\ty2.push( y1 );\n\t\t\t}\n\t\t\ty3.push( y2 );\n\t\t}\n\t\ty.push( y3 );\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = map5d;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Applies a function to elements in a five-dimensional nested input array and assigns results to elements in a five-dimensional nested output array.\n*\n* ## Notes\n*\n* - The function assumes that the input and output arrays have the same shape.\n*\n* @param {ArrayLikeObject<Collection>} x - input nested array\n* @param {ArrayLikeObject<Collection>} y - output nested array\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {Function} fcn - function to apply\n* @param {*} [thisArg] - function execution context\n* @returns {Array<Array>} output array\n*\n* @example\n* var ones5d = require( '@stdlib/array-base-ones5d' );\n* var zeros5d = require( '@stdlib/array-base-zeros5d' );\n*\n* function scale( x ) {\n* return x * 10.0;\n* }\n*\n* var shape = [ 1, 1, 1, 2, 2 ];\n*\n* var x = ones5d( shape );\n* var y = zeros5d( shape );\n*\n* var out = map5d( x, y, shape, scale );\n* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]\n*\n* var bool = ( out === y );\n* // returns true\n*/\nfunction map5d( x, y, shape, fcn, thisArg ) {\n\tvar S0;\n\tvar S1;\n\tvar S2;\n\tvar S3;\n\tvar S4;\n\tvar i0;\n\tvar i1;\n\tvar i2;\n\tvar i3;\n\tvar i4;\n\tvar x0;\n\tvar y0;\n\tvar x1;\n\tvar y1;\n\tvar x2;\n\tvar y2;\n\tvar x3;\n\tvar y3;\n\n\tS0 = shape[ 4 ];\n\tS1 = shape[ 3 ];\n\tS2 = shape[ 2 ];\n\tS3 = shape[ 1 ];\n\tS4 = shape[ 0 ];\n\tif ( S0 <= 0 || S1 <= 0 || S2 <= 0 || S3 <= 0 || S4 <= 0 ) {\n\t\treturn y;\n\t}\n\tfor ( i4 = 0; i4 < S4; i4++ ) {\n\t\tx3 = x[ i4 ];\n\t\ty3 = y[ i4 ];\n\t\tfor ( i3 = 0; i3 < S3; i3++ ) {\n\t\t\tx2 = x3[ i3 ];\n\t\t\ty2 = y3[ i3 ];\n\t\t\tfor ( i2 = 0; i2 < S2; i2++ ) {\n\t\t\t\tx1 = x2[ i2 ];\n\t\t\t\ty1 = y2[ i2 ];\n\t\t\t\tfor ( i1 = 0; i1 < S1; i1++ ) {\n\t\t\t\t\tx0 = x1[ i1 ];\n\t\t\t\t\ty0 = y1[ i1 ];\n\t\t\t\t\tfor ( i0 = 0; i0 < S0; i0++ ) {\n\t\t\t\t\t\ty0[ i0 ] = fcn.call( thisArg, x0[ i0 ], [ i4, i3, i2, i1, i0 ], x ); // eslint-disable-line max-len\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = map5d;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Apply a function to elements in a five-dimensional nested input array and assign results to elements in a new five-dimensional nested output array.\n*\n* @module @stdlib/array-base-map5d\n*\n* @example\n* var ones5d = require( '@stdlib/array-base-ones5d' );\n* var map5d = require( '@stdlib/array-base-map5d' );\n*\n* function scale( x ) {\n* return x * 10.0;\n* }\n*\n* var shape = [ 1, 1, 1, 2, 2 ];\n*\n* var x = ones5d( shape );\n* var y = map5d( x, shape, scale );\n* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]\n*\n* @example\n* var ones5d = require( '@stdlib/array-base-ones5d' );\n* var zeros5d = require( '@stdlib/array-base-zeros5d' );\n* var map5d = require( '@stdlib/array-base-map5d' );\n*\n* function scale( x ) {\n* return x * 10.0;\n* }\n*\n* var shape = [ 1, 1, 1, 2, 2 ];\n*\n* var x = ones5d( shape );\n* var y = zeros5d( shape );\n*\n* var out = map5d.assign( x, y, shape, scale );\n* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]\n*\n* var bool = ( out === y );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4CA,SAASC,EAAOC,EAAGC,EAAOC,EAAKC,EAAU,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,IANAlB,EAAKH,EAAO,CAAE,EACdI,EAAKJ,EAAO,CAAE,EACdK,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EACdO,EAAKP,EAAO,CAAE,EACdqB,EAAI,CAAC,EACCT,EAAK,EAAGA,EAAKL,EAAIK,IAAO,CAG7B,IAFAO,EAAKpB,EAAGa,CAAG,EACXQ,EAAK,CAAC,EACAT,EAAK,EAAGA,EAAKL,EAAIK,IAAO,CAG7B,IAFAM,EAAKE,EAAIR,CAAG,EACZO,EAAK,CAAC,EACAR,EAAK,EAAGA,EAAKL,EAAIK,IAAO,CAG7B,IAFAK,EAAKE,EAAIP,CAAG,EACZM,EAAK,CAAC,EACAP,EAAK,EAAGA,EAAKL,EAAIK,IAAO,CAG7B,IAFAI,EAAKE,EAAIN,CAAG,EACZK,EAAK,CAAC,EACAN,EAAK,EAAGA,EAAKL,EAAIK,IACtBM,EAAG,KAAMb,EAAI,KAAMC,EAASW,EAAIL,CAAG,EAAG,CAAEI,EAAID,EAAID,EAAID,EAAID,CAAG,EAAGT,CAAE,CAAE,EAEnEiB,EAAG,KAAMF,CAAG,CACb,CACAI,EAAG,KAAMF,CAAG,CACb,CACAI,EAAG,KAAMF,CAAG,CACb,CACAG,EAAE,KAAMD,CAAG,CACZ,CACA,OAAOC,CACR,CAKAxB,EAAO,QAAUC,ICpGjB,IAAAwB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAuDA,SAASC,EAAOC,EAAGC,EAAGC,EAAOC,EAAKC,EAAU,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAjB,EAAKH,EAAO,CAAE,EACdI,EAAKJ,EAAO,CAAE,EACdK,EAAKL,EAAO,CAAE,EACdM,EAAKN,EAAO,CAAE,EACdO,EAAKP,EAAO,CAAE,EACTG,GAAM,GAAKC,GAAM,GAAKC,GAAM,GAAKC,GAAM,GAAKC,GAAM,EACtD,OAAOR,EAER,IAAMa,EAAK,EAAGA,EAAKL,EAAIK,IAGtB,IAFAO,EAAKrB,EAAGc,CAAG,EACXQ,EAAKrB,EAAGa,CAAG,EACLD,EAAK,EAAGA,EAAKL,EAAIK,IAGtB,IAFAM,EAAKE,EAAIR,CAAG,EACZO,EAAKE,EAAIT,CAAG,EACND,EAAK,EAAGA,EAAKL,EAAIK,IAGtB,IAFAK,EAAKE,EAAIP,CAAG,EACZM,EAAKE,EAAIR,CAAG,EACND,EAAK,EAAGA,EAAKL,EAAIK,IAGtB,IAFAI,EAAKE,EAAIN,CAAG,EACZK,EAAKE,EAAIP,CAAG,EACND,EAAK,EAAGA,EAAKL,EAAIK,IACtBM,EAAIN,CAAG,EAAIP,EAAI,KAAMC,EAASW,EAAIL,CAAG,EAAG,CAAEI,EAAID,EAAID,EAAID,EAAID,CAAG,EAAGV,CAAE,EAMvE,OAAOC,CACR,CAKAH,EAAO,QAAUC,IC9CjB,IAAIwB,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "map5d", "x", "shape", "fcn", "thisArg", "S0", "S1", "S2", "S3", "S4", "i0", "i1", "i2", "i3", "i4", "x0", "y0", "x1", "y1", "x2", "y2", "x3", "y3", "y", "require_assign", "__commonJSMin", "exports", "module", "map5d", "x", "y", "shape", "fcn", "thisArg", "S0", "S1", "S2", "S3", "S4", "i0", "i1", "i2", "i3", "i4", "x0", "y0", "x1", "y1", "x2", "y2", "x3", "y3", "setReadOnly", "main", "assign"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
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 { Array5D } from '@stdlib/types/array';
|
|
24
|
+
import { Shape5D } from '@stdlib/types/ndarray';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Array element indices.
|
|
28
|
+
*/
|
|
29
|
+
type Indices = [ number, number, number, number, number ];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Callback invoked for each array element.
|
|
33
|
+
*
|
|
34
|
+
* @returns result
|
|
35
|
+
*/
|
|
36
|
+
type Nullary<U, V> = ( this: V ) => U;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Callback invoked for each array element.
|
|
40
|
+
*
|
|
41
|
+
* @param value - array element
|
|
42
|
+
* @returns result
|
|
43
|
+
*/
|
|
44
|
+
type Unary<T, U, V> = ( this: V, value: T ) => U;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Callback invoked for each array element.
|
|
48
|
+
*
|
|
49
|
+
* @param value - array element
|
|
50
|
+
* @param indices - current array element indices
|
|
51
|
+
* @returns result
|
|
52
|
+
*/
|
|
53
|
+
type Binary<T, U, V> = ( this: V, value: T, indices: Indices ) => U;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Callback invoked for each array element.
|
|
57
|
+
*
|
|
58
|
+
* @param value - array element
|
|
59
|
+
* @param indices - current array element indices
|
|
60
|
+
* @param array - input array
|
|
61
|
+
* @returns result
|
|
62
|
+
*/
|
|
63
|
+
type Ternary<T, U, V> = ( this: V, value: T, indices: Indices, array: Array5D<T> ) => U;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Callback invoked for each array element.
|
|
67
|
+
*
|
|
68
|
+
* @param value - array element
|
|
69
|
+
* @param indices - current array element indices
|
|
70
|
+
* @param array - input array
|
|
71
|
+
* @returns result
|
|
72
|
+
*/
|
|
73
|
+
type Callback<T, U, V> = Nullary<U, V> | Unary<T, U, V> | Binary<T, U, V> | Ternary<T, U, V>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Interface describing the main export.
|
|
77
|
+
*/
|
|
78
|
+
interface Routine {
|
|
79
|
+
/**
|
|
80
|
+
* Applies a function to elements in a five-dimensional nested input array and assigns results to elements in a new five-dimensional nested output array.
|
|
81
|
+
*
|
|
82
|
+
* @param x - input nested array
|
|
83
|
+
* @param shape - array shape
|
|
84
|
+
* @param fcn - function to apply
|
|
85
|
+
* @param thisArg - function execution context
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* var ones5d = require( `@stdlib/array/base/ones5d` );
|
|
89
|
+
*
|
|
90
|
+
* function scale( x ) {
|
|
91
|
+
* return x * 10.0;
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* var shape = [ 1, 1, 1, 2, 2 ];
|
|
95
|
+
*
|
|
96
|
+
* var x = ones5d( shape );
|
|
97
|
+
* var y = map5d( x, shape, scale );
|
|
98
|
+
* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]
|
|
99
|
+
*/
|
|
100
|
+
<T = unknown, U = unknown, V = unknown>( x: Array5D<T>, shape: Shape5D, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): Array5D<U>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Applies a function to elements in a five-dimensional nested input array and assigns results to elements in a five-dimensional nested output array.
|
|
104
|
+
*
|
|
105
|
+
* @param x - input nested array
|
|
106
|
+
* @param y - output nested array
|
|
107
|
+
* @param shape - array shape
|
|
108
|
+
* @param fcn - function to apply
|
|
109
|
+
* @param thisArg - function execution context
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* var ones5d = require( `@stdlib/array/base/ones5d` );
|
|
113
|
+
* var zeros5d = require( `@stdlib/array/base/zeros5d` );
|
|
114
|
+
*
|
|
115
|
+
* function scale( x ) {
|
|
116
|
+
* return x * 10.0;
|
|
117
|
+
* }
|
|
118
|
+
*
|
|
119
|
+
* var shape = [ 1, 1, 1, 2, 2 ];
|
|
120
|
+
*
|
|
121
|
+
* var x = ones5d( shape );
|
|
122
|
+
* var y = zeros5d( shape );
|
|
123
|
+
*
|
|
124
|
+
* var out = map5d.assign( x, y, shape, scale );
|
|
125
|
+
* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]
|
|
126
|
+
*
|
|
127
|
+
* var bool = ( out === y );
|
|
128
|
+
* // returns true
|
|
129
|
+
*/
|
|
130
|
+
assign<T = unknown, U = unknown, V = unknown>( x: Array5D<T>, y: Array5D<U>, shape: Shape5D, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): Array5D<U>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Applies a function to elements in a five-dimensional nested input array and assigns results to elements in a new five-dimensional nested output array.
|
|
135
|
+
*
|
|
136
|
+
* ## Notes
|
|
137
|
+
*
|
|
138
|
+
* - The applied function is provided the following arguments:
|
|
139
|
+
*
|
|
140
|
+
* - **value**: array element.
|
|
141
|
+
* - **indices**: current array element indices.
|
|
142
|
+
* -- **array**: input nested array.
|
|
143
|
+
*
|
|
144
|
+
* @param x - input nested array
|
|
145
|
+
* @param shape - array shape
|
|
146
|
+
* @param fcn - function to apply
|
|
147
|
+
* @param thisArg - function execution context
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* var ones5d = require( `@stdlib/array/base/ones5d` );
|
|
151
|
+
*
|
|
152
|
+
* function scale( x ) {
|
|
153
|
+
* return x * 10.0;
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* var shape = [ 1, 1, 1, 2, 2 ];
|
|
157
|
+
*
|
|
158
|
+
* var x = ones5d( shape );
|
|
159
|
+
* var y = map5d( x, shape, scale );
|
|
160
|
+
* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* var ones5d = require( `@stdlib/array/base/ones5d` );
|
|
164
|
+
* var zeros5d = require( `@stdlib/array/base/zeros5d` );
|
|
165
|
+
*
|
|
166
|
+
* function scale( x ) {
|
|
167
|
+
* return x * 10.0;
|
|
168
|
+
* }
|
|
169
|
+
*
|
|
170
|
+
* var shape = [ 1, 1, 1, 2, 2 ];
|
|
171
|
+
*
|
|
172
|
+
* var x = ones5d( shape );
|
|
173
|
+
* var y = zeros5d( shape );
|
|
174
|
+
*
|
|
175
|
+
* var out = map5d.assign( x, y, shape, scale );
|
|
176
|
+
* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]
|
|
177
|
+
*
|
|
178
|
+
* var bool = ( out === y );
|
|
179
|
+
* // returns true
|
|
180
|
+
*/
|
|
181
|
+
declare var map5d: Routine;
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
// EXPORTS //
|
|
185
|
+
|
|
186
|
+
export = map5d;
|
package/lib/assign.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
// MAIN //
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Applies a function to elements in a five-dimensional nested input array and assigns results to elements in a five-dimensional nested output array.
|
|
25
|
+
*
|
|
26
|
+
* ## Notes
|
|
27
|
+
*
|
|
28
|
+
* - The function assumes that the input and output arrays have the same shape.
|
|
29
|
+
*
|
|
30
|
+
* @param {ArrayLikeObject<Collection>} x - input nested array
|
|
31
|
+
* @param {ArrayLikeObject<Collection>} y - output nested array
|
|
32
|
+
* @param {NonNegativeIntegerArray} shape - array shape
|
|
33
|
+
* @param {Function} fcn - function to apply
|
|
34
|
+
* @param {*} [thisArg] - function execution context
|
|
35
|
+
* @returns {Array<Array>} output array
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var ones5d = require( '@stdlib/array-base-ones5d' );
|
|
39
|
+
* var zeros5d = require( '@stdlib/array-base-zeros5d' );
|
|
40
|
+
*
|
|
41
|
+
* function scale( x ) {
|
|
42
|
+
* return x * 10.0;
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* var shape = [ 1, 1, 1, 2, 2 ];
|
|
46
|
+
*
|
|
47
|
+
* var x = ones5d( shape );
|
|
48
|
+
* var y = zeros5d( shape );
|
|
49
|
+
*
|
|
50
|
+
* var out = map5d( x, y, shape, scale );
|
|
51
|
+
* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]
|
|
52
|
+
*
|
|
53
|
+
* var bool = ( out === y );
|
|
54
|
+
* // returns true
|
|
55
|
+
*/
|
|
56
|
+
function map5d( x, y, shape, fcn, thisArg ) {
|
|
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 x0;
|
|
68
|
+
var y0;
|
|
69
|
+
var x1;
|
|
70
|
+
var y1;
|
|
71
|
+
var x2;
|
|
72
|
+
var y2;
|
|
73
|
+
var x3;
|
|
74
|
+
var y3;
|
|
75
|
+
|
|
76
|
+
S0 = shape[ 4 ];
|
|
77
|
+
S1 = shape[ 3 ];
|
|
78
|
+
S2 = shape[ 2 ];
|
|
79
|
+
S3 = shape[ 1 ];
|
|
80
|
+
S4 = shape[ 0 ];
|
|
81
|
+
if ( S0 <= 0 || S1 <= 0 || S2 <= 0 || S3 <= 0 || S4 <= 0 ) {
|
|
82
|
+
return y;
|
|
83
|
+
}
|
|
84
|
+
for ( i4 = 0; i4 < S4; i4++ ) {
|
|
85
|
+
x3 = x[ i4 ];
|
|
86
|
+
y3 = y[ i4 ];
|
|
87
|
+
for ( i3 = 0; i3 < S3; i3++ ) {
|
|
88
|
+
x2 = x3[ i3 ];
|
|
89
|
+
y2 = y3[ i3 ];
|
|
90
|
+
for ( i2 = 0; i2 < S2; i2++ ) {
|
|
91
|
+
x1 = x2[ i2 ];
|
|
92
|
+
y1 = y2[ i2 ];
|
|
93
|
+
for ( i1 = 0; i1 < S1; i1++ ) {
|
|
94
|
+
x0 = x1[ i1 ];
|
|
95
|
+
y0 = y1[ i1 ];
|
|
96
|
+
for ( i0 = 0; i0 < S0; i0++ ) {
|
|
97
|
+
y0[ i0 ] = fcn.call( thisArg, x0[ i0 ], [ i4, i3, i2, i1, i0 ], x ); // eslint-disable-line max-len
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return y;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
// EXPORTS //
|
|
108
|
+
|
|
109
|
+
module.exports = map5d;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
* Apply a function to elements in a five-dimensional nested input array and assign results to elements in a new five-dimensional nested output array.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/array-base-map5d
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var ones5d = require( '@stdlib/array-base-ones5d' );
|
|
28
|
+
* var map5d = require( '@stdlib/array-base-map5d' );
|
|
29
|
+
*
|
|
30
|
+
* function scale( x ) {
|
|
31
|
+
* return x * 10.0;
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* var shape = [ 1, 1, 1, 2, 2 ];
|
|
35
|
+
*
|
|
36
|
+
* var x = ones5d( shape );
|
|
37
|
+
* var y = map5d( x, shape, scale );
|
|
38
|
+
* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var ones5d = require( '@stdlib/array-base-ones5d' );
|
|
42
|
+
* var zeros5d = require( '@stdlib/array-base-zeros5d' );
|
|
43
|
+
* var map5d = require( '@stdlib/array-base-map5d' );
|
|
44
|
+
*
|
|
45
|
+
* function scale( x ) {
|
|
46
|
+
* return x * 10.0;
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* var shape = [ 1, 1, 1, 2, 2 ];
|
|
50
|
+
*
|
|
51
|
+
* var x = ones5d( shape );
|
|
52
|
+
* var y = zeros5d( shape );
|
|
53
|
+
*
|
|
54
|
+
* var out = map5d.assign( x, y, shape, scale );
|
|
55
|
+
* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]
|
|
56
|
+
*
|
|
57
|
+
* var bool = ( out === y );
|
|
58
|
+
* // returns true
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
// MODULES //
|
|
62
|
+
|
|
63
|
+
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
64
|
+
var main = require( './main.js' );
|
|
65
|
+
var assign = require( './assign.js' );
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
// MAIN //
|
|
69
|
+
|
|
70
|
+
setReadOnly( main, 'assign', assign );
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
// EXPORTS //
|
|
74
|
+
|
|
75
|
+
module.exports = main;
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
// MAIN //
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Applies a function to elements in a five-dimensional nested input array and assigns results to elements in a new five-dimensional nested output array.
|
|
25
|
+
*
|
|
26
|
+
* @param {ArrayLikeObject<Collection>} x - input nested array
|
|
27
|
+
* @param {NonNegativeIntegerArray} shape - array shape
|
|
28
|
+
* @param {Function} fcn - function to apply
|
|
29
|
+
* @param {*} [thisArg] - function execution context
|
|
30
|
+
* @returns {Array<Array>} output array
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* var ones5d = require( '@stdlib/array-base-ones5d' );
|
|
34
|
+
*
|
|
35
|
+
* function scale( x ) {
|
|
36
|
+
* return x * 10.0;
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* var shape = [ 1, 1, 1, 2, 2 ];
|
|
40
|
+
*
|
|
41
|
+
* var x = ones5d( shape );
|
|
42
|
+
* var y = map5d( x, shape, scale );
|
|
43
|
+
* // returns [ [ [ [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] ] ] ]
|
|
44
|
+
*/
|
|
45
|
+
function map5d( x, shape, fcn, thisArg ) {
|
|
46
|
+
var S0;
|
|
47
|
+
var S1;
|
|
48
|
+
var S2;
|
|
49
|
+
var S3;
|
|
50
|
+
var S4;
|
|
51
|
+
var i0;
|
|
52
|
+
var i1;
|
|
53
|
+
var i2;
|
|
54
|
+
var i3;
|
|
55
|
+
var i4;
|
|
56
|
+
var x0;
|
|
57
|
+
var y0;
|
|
58
|
+
var x1;
|
|
59
|
+
var y1;
|
|
60
|
+
var x2;
|
|
61
|
+
var y2;
|
|
62
|
+
var x3;
|
|
63
|
+
var y3;
|
|
64
|
+
var y;
|
|
65
|
+
|
|
66
|
+
S0 = shape[ 4 ];
|
|
67
|
+
S1 = shape[ 3 ];
|
|
68
|
+
S2 = shape[ 2 ];
|
|
69
|
+
S3 = shape[ 1 ];
|
|
70
|
+
S4 = shape[ 0 ];
|
|
71
|
+
y = [];
|
|
72
|
+
for ( i4 = 0; i4 < S4; i4++ ) {
|
|
73
|
+
x3 = x[ i4 ];
|
|
74
|
+
y3 = [];
|
|
75
|
+
for ( i3 = 0; i3 < S3; i3++ ) {
|
|
76
|
+
x2 = x3[ i3 ];
|
|
77
|
+
y2 = [];
|
|
78
|
+
for ( i2 = 0; i2 < S2; i2++ ) {
|
|
79
|
+
x1 = x2[ i2 ];
|
|
80
|
+
y1 = [];
|
|
81
|
+
for ( i1 = 0; i1 < S1; i1++ ) {
|
|
82
|
+
x0 = x1[ i1 ];
|
|
83
|
+
y0 = [];
|
|
84
|
+
for ( i0 = 0; i0 < S0; i0++ ) {
|
|
85
|
+
y0.push( fcn.call( thisArg, x0[ i0 ], [ i4, i3, i2, i1, i0 ], x ) ); // eslint-disable-line max-len
|
|
86
|
+
}
|
|
87
|
+
y1.push( y0 );
|
|
88
|
+
}
|
|
89
|
+
y2.push( y1 );
|
|
90
|
+
}
|
|
91
|
+
y3.push( y2 );
|
|
92
|
+
}
|
|
93
|
+
y.push( y3 );
|
|
94
|
+
}
|
|
95
|
+
return y;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
// EXPORTS //
|
|
100
|
+
|
|
101
|
+
module.exports = map5d;
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/array-base-map5d",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Apply a function to elements in a five-dimensional nested input array and assign results to elements in a new five-dimensional nested output 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-map5d.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@stdlib/types": "^0.2.0",
|
|
41
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@stdlib/array-base-filled5d-by": "^0.1.0",
|
|
45
|
+
"@stdlib/array-base-zeros5d": "^0.1.0",
|
|
46
|
+
"@stdlib/math-base-assert-is-nan": "^0.1.1",
|
|
47
|
+
"@stdlib/math-base-special-abs": "^0.1.1",
|
|
48
|
+
"@stdlib/math-base-special-floor": "^0.1.1",
|
|
49
|
+
"@stdlib/math-base-special-identity": "^0.1.1",
|
|
50
|
+
"@stdlib/math-base-special-pow": "^0.1.0",
|
|
51
|
+
"@stdlib/ndarray-base-numel": "^0.1.1",
|
|
52
|
+
"@stdlib/random-base-discrete-uniform": "^0.1.0",
|
|
53
|
+
"@stdlib/random-base-uniform": "^0.1.0",
|
|
54
|
+
"@stdlib/utils-nary-function": "^0.1.0",
|
|
55
|
+
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
56
|
+
"istanbul": "^0.4.1",
|
|
57
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",
|
|
58
|
+
"@stdlib/bench-harness": "^0.1.2",
|
|
59
|
+
"@stdlib/bench": "^0.2.1"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=0.10.0",
|
|
63
|
+
"npm": ">2.7.0"
|
|
64
|
+
},
|
|
65
|
+
"os": [
|
|
66
|
+
"aix",
|
|
67
|
+
"darwin",
|
|
68
|
+
"freebsd",
|
|
69
|
+
"linux",
|
|
70
|
+
"macos",
|
|
71
|
+
"openbsd",
|
|
72
|
+
"sunos",
|
|
73
|
+
"win32",
|
|
74
|
+
"windows"
|
|
75
|
+
],
|
|
76
|
+
"keywords": [
|
|
77
|
+
"stdlib",
|
|
78
|
+
"base",
|
|
79
|
+
"array",
|
|
80
|
+
"multidimensional",
|
|
81
|
+
"ndarray",
|
|
82
|
+
"matrix",
|
|
83
|
+
"5d",
|
|
84
|
+
"apply",
|
|
85
|
+
"foreach",
|
|
86
|
+
"map",
|
|
87
|
+
"transform"
|
|
88
|
+
],
|
|
89
|
+
"__stdlib__": {},
|
|
90
|
+
"funding": {
|
|
91
|
+
"type": "opencollective",
|
|
92
|
+
"url": "https://opencollective.com/stdlib"
|
|
93
|
+
}
|
|
94
|
+
}
|