@stdlib/utils-map2-right 0.0.1 → 0.2.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 +0 -304
- package/NOTICE +1 -1
- package/README.md +46 -17
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +42 -71
- package/lib/array.js +10 -10
- package/lib/assign.js +9 -9
- package/lib/main.js +7 -7
- package/lib/ndarray.js +11 -11
- package/package.json +35 -32
- package/docs/repl.txt +0 -129
- package/docs/types/test.ts +0 -343
package/docs/types/index.d.ts
CHANGED
|
@@ -16,19 +16,19 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
// TypeScript Version:
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
20
|
|
|
21
21
|
/// <reference types="@stdlib/types"/>
|
|
22
22
|
|
|
23
|
-
import { Collection } from '@stdlib/types/
|
|
24
|
-
import {
|
|
23
|
+
import { Collection } from '@stdlib/types/array';
|
|
24
|
+
import { typedndarray } from '@stdlib/types/ndarray';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Callback invoked for each pair of array elements.
|
|
28
28
|
*
|
|
29
29
|
* @returns result
|
|
30
30
|
*/
|
|
31
|
-
type Nullary = () =>
|
|
31
|
+
type Nullary<V, W> = ( this: W ) => V;
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Callback invoked for each pair of array elements.
|
|
@@ -36,7 +36,7 @@ type Nullary = () => any;
|
|
|
36
36
|
* @param v1 - element from the first input array
|
|
37
37
|
* @returns result
|
|
38
38
|
*/
|
|
39
|
-
type Unary = ( v1:
|
|
39
|
+
type Unary<T, V, W> = ( this: W, v1: T ) => V;
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Callback invoked for each pair of array elements.
|
|
@@ -45,7 +45,7 @@ type Unary = ( v1: any ) => any;
|
|
|
45
45
|
* @param v2 - element from the second input array
|
|
46
46
|
* @returns result
|
|
47
47
|
*/
|
|
48
|
-
type Binary = ( v1:
|
|
48
|
+
type Binary<T, U, V, W> = ( this: W, v1: T, v2: U ) => V;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Callback invoked for each pair of array elements.
|
|
@@ -55,7 +55,7 @@ type Binary = ( v1: any, v2: any ) => any;
|
|
|
55
55
|
* @param index - element index
|
|
56
56
|
* @returns result
|
|
57
57
|
*/
|
|
58
|
-
type Ternary = ( v1:
|
|
58
|
+
type Ternary<T, U, V, W> = ( this: W, v1: T, v2: U, index: number ) => V;
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* Callback invoked for each pair of array elements.
|
|
@@ -63,33 +63,10 @@ type Ternary = ( v1: any, v2: any, index: number ) => any;
|
|
|
63
63
|
* @param v1 - element from the first input array
|
|
64
64
|
* @param v2 - element from the second input array
|
|
65
65
|
* @param index - element index
|
|
66
|
-
* @param
|
|
67
|
-
* @returns result
|
|
68
|
-
*/
|
|
69
|
-
type Quaternary = ( v1: any, v2: any, index: number, x: ndarray ) => any;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Callback invoked for each pair of array elements.
|
|
73
|
-
*
|
|
74
|
-
* @param v1 - element from the first input array
|
|
75
|
-
* @param v2 - element from the second input array
|
|
76
|
-
* @param index - element index
|
|
77
|
-
* @param x - first input array
|
|
78
|
-
* @returns result
|
|
79
|
-
*/
|
|
80
|
-
type ArrayQuaternary = ( v1: any, v2: any, index: number, x: Collection ) => any; // tslint:disable-line:max-line-length
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Callback invoked for each pair of array elements.
|
|
84
|
-
*
|
|
85
|
-
* @param v1 - element from the first input array
|
|
86
|
-
* @param v2 - element from the second input array
|
|
87
|
-
* @param index - element index
|
|
88
|
-
* @param x - first input array
|
|
89
|
-
* @param y - second input array
|
|
66
|
+
* @param arrays - input arrays
|
|
90
67
|
* @returns result
|
|
91
68
|
*/
|
|
92
|
-
type
|
|
69
|
+
type Quaternary<T, U, V, W> = ( this: W, v1: T, v2: U, index: number, arrays: [ typedndarray<T>, typedndarray<U> ] ) => V;
|
|
93
70
|
|
|
94
71
|
/**
|
|
95
72
|
* Callback invoked for each pair of array elements.
|
|
@@ -97,11 +74,10 @@ type Quinary = ( v1: any, v2: any, index: number, x: ndarray, y: ndarray ) => an
|
|
|
97
74
|
* @param v1 - element from the first input array
|
|
98
75
|
* @param v2 - element from the second input array
|
|
99
76
|
* @param index - element index
|
|
100
|
-
* @param
|
|
101
|
-
* @param y - second input array
|
|
77
|
+
* @param arrays - input arrays
|
|
102
78
|
* @returns result
|
|
103
79
|
*/
|
|
104
|
-
type
|
|
80
|
+
type ArrayQuaternary<T, U, V, W> = ( this: W, v1: T, v2: U, index: number, arrays: [ Collection<T>, Collection<U> ] ) => V;
|
|
105
81
|
|
|
106
82
|
/**
|
|
107
83
|
* Callback invoked for each pair of array elements.
|
|
@@ -113,7 +89,7 @@ type ArrayQuinary = ( v1: any, v2: any, index: number, x: Collection, y: Collect
|
|
|
113
89
|
* @param y - second input array
|
|
114
90
|
* @returns result
|
|
115
91
|
*/
|
|
116
|
-
type Callback = Nullary | Unary | Binary | Ternary | Quaternary
|
|
92
|
+
type Callback<T, U, V, W> = Nullary<V, W> | Unary<T, V, W> | Binary<T, U, V, W> | Ternary<T, U, V, W> | Quaternary<T, U, V, W>;
|
|
117
93
|
|
|
118
94
|
/**
|
|
119
95
|
* Callback invoked for each pair of array elements.
|
|
@@ -125,7 +101,7 @@ type Callback = Nullary | Unary | Binary | Ternary | Quaternary | Quinary;
|
|
|
125
101
|
* @param y - second input array
|
|
126
102
|
* @returns result
|
|
127
103
|
*/
|
|
128
|
-
type ArrayCallback = Nullary | Unary | Binary | Ternary | ArrayQuaternary
|
|
104
|
+
type ArrayCallback<T, U, V, W> = Nullary<V, W> | Unary<T, V, W> | Binary<T, U, V, W> | Ternary<T, U, V, W> | ArrayQuaternary<T, U, V, W>;
|
|
129
105
|
|
|
130
106
|
/**
|
|
131
107
|
* Interface describing the main export.
|
|
@@ -143,8 +119,7 @@ interface Routine {
|
|
|
143
119
|
* - **v1**: element from first input array.
|
|
144
120
|
* - **v2**: element from second input array.
|
|
145
121
|
* - **idx**: element index.
|
|
146
|
-
* - **
|
|
147
|
-
* - **y**: second input array.
|
|
122
|
+
* - **arrays**: input arrays.
|
|
148
123
|
*
|
|
149
124
|
* @param x - first input array
|
|
150
125
|
* @param y - second input array
|
|
@@ -153,9 +128,9 @@ interface Routine {
|
|
|
153
128
|
* @returns output array
|
|
154
129
|
*
|
|
155
130
|
* @example
|
|
156
|
-
* var naryFunction = require(
|
|
157
|
-
* var add = require(
|
|
158
|
-
* var array = require(
|
|
131
|
+
* var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
132
|
+
* var add = require( '@stdlib/math-base-ops-add' );
|
|
133
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
159
134
|
*
|
|
160
135
|
* var opts = {
|
|
161
136
|
* 'dtype': 'generic'
|
|
@@ -169,7 +144,7 @@ interface Routine {
|
|
|
169
144
|
* var data = out.data;
|
|
170
145
|
* // returns [ 2, 3, 4, 5, 6, 7 ]
|
|
171
146
|
*/
|
|
172
|
-
( x:
|
|
147
|
+
<T = unknown, U = unknown, V = unknown, W = unknown>( x: typedndarray<T>, y: typedndarray<U>, fcn: Callback<T, U, V, W>, thisArg?: ThisParameterType<Callback<T, U, V, W>> ): typedndarray<V>;
|
|
173
148
|
|
|
174
149
|
/**
|
|
175
150
|
* Applies a function to elements in two input arrays while iterating from right to left and assigns the results to a new array.
|
|
@@ -181,8 +156,7 @@ interface Routine {
|
|
|
181
156
|
* - **v1**: element from first input array.
|
|
182
157
|
* - **v2**: element from second input array.
|
|
183
158
|
* - **idx**: element index.
|
|
184
|
-
* - **
|
|
185
|
-
* - **y**: second input array.
|
|
159
|
+
* - **arrays**: input arrays.
|
|
186
160
|
*
|
|
187
161
|
* @param x - first input array
|
|
188
162
|
* @param y - second input array
|
|
@@ -191,8 +165,8 @@ interface Routine {
|
|
|
191
165
|
* @returns output array
|
|
192
166
|
*
|
|
193
167
|
* @example
|
|
194
|
-
* var naryFunction = require(
|
|
195
|
-
* var add = require(
|
|
168
|
+
* var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
169
|
+
* var add = require( '@stdlib/math-base-ops-add' );
|
|
196
170
|
*
|
|
197
171
|
* var x = [ 1, 2, 3, 4, 5, 6 ];
|
|
198
172
|
* var y = [ 1, 1, 1, 1, 1, 1 ];
|
|
@@ -200,7 +174,7 @@ interface Routine {
|
|
|
200
174
|
* var out = map2Right( x, y, naryFunction( add, 2 ) );
|
|
201
175
|
* // returns [ 2, 3, 4, 5, 6, 7 ]
|
|
202
176
|
*/
|
|
203
|
-
( x: Collection
|
|
177
|
+
<T = unknown, U = unknown, V = unknown, W = unknown>( x: Collection<T>, y: Collection<U>, fcn: ArrayCallback<T, U, V, W>, thisArg?: ThisParameterType<ArrayCallback<T, U, V, W>> ): Collection<V>;
|
|
204
178
|
|
|
205
179
|
/**
|
|
206
180
|
* Applies a function to elements in two input arrays while iterating from right to left and assigns the results to an output array.
|
|
@@ -212,8 +186,7 @@ interface Routine {
|
|
|
212
186
|
* - **v1**: element from first input array.
|
|
213
187
|
* - **v2**: element from second input array.
|
|
214
188
|
* - **idx**: element index.
|
|
215
|
-
* - **
|
|
216
|
-
* - **y**: second input array.
|
|
189
|
+
* - **arrays**: input arrays.
|
|
217
190
|
*
|
|
218
191
|
* @param x - first input array
|
|
219
192
|
* @param y - second input array
|
|
@@ -223,9 +196,9 @@ interface Routine {
|
|
|
223
196
|
* @returns output array
|
|
224
197
|
*
|
|
225
198
|
* @example
|
|
226
|
-
* var naryFunction = require(
|
|
227
|
-
* var add = require(
|
|
228
|
-
* var array = require(
|
|
199
|
+
* var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
200
|
+
* var add = require( '@stdlib/math-base-ops-add' );
|
|
201
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
229
202
|
*
|
|
230
203
|
* var opts = {
|
|
231
204
|
* 'dtype': 'generic',
|
|
@@ -240,7 +213,7 @@ interface Routine {
|
|
|
240
213
|
* var data = out.data;
|
|
241
214
|
* // returns [ 2, 3, 4, 5, 6, 7 ]
|
|
242
215
|
*/
|
|
243
|
-
assign( x:
|
|
216
|
+
assign<T = unknown, U = unknown, V = unknown, W = unknown>( x: typedndarray<T>, y: typedndarray<U>, out: typedndarray<V>, fcn: Callback<T, U, V, W>, thisArg?: ThisParameterType<Callback<T, U, V, W>> ): typedndarray<V>;
|
|
244
217
|
|
|
245
218
|
/**
|
|
246
219
|
* Applies a function to elements in two input arrays while iterating from right to left and assigns the results to an output array.
|
|
@@ -252,8 +225,7 @@ interface Routine {
|
|
|
252
225
|
* - **v1**: element from first input array.
|
|
253
226
|
* - **v2**: element from second input array.
|
|
254
227
|
* - **idx**: element index.
|
|
255
|
-
* - **
|
|
256
|
-
* - **y**: second input array.
|
|
228
|
+
* - **arrays**: input arrays.
|
|
257
229
|
*
|
|
258
230
|
* @param x - first input array
|
|
259
231
|
* @param y - second input array
|
|
@@ -263,8 +235,8 @@ interface Routine {
|
|
|
263
235
|
* @returns output array
|
|
264
236
|
*
|
|
265
237
|
* @example
|
|
266
|
-
* var naryFunction = require(
|
|
267
|
-
* var add = require(
|
|
238
|
+
* var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
239
|
+
* var add = require( '@stdlib/math-base-ops-add' );
|
|
268
240
|
*
|
|
269
241
|
* var x = [ 1, 2, 3, 4, 5, 6 ];
|
|
270
242
|
* var y = [ 1, 1, 1, 1, 1, 1 ];
|
|
@@ -275,7 +247,7 @@ interface Routine {
|
|
|
275
247
|
* console.log( out );
|
|
276
248
|
* // => [ 2, 3, 4, 5, 6, 7 ]
|
|
277
249
|
*/
|
|
278
|
-
assign( x: Collection
|
|
250
|
+
assign<T = unknown, U = unknown, V = unknown, W = unknown>( x: Collection<T>, y: Collection<U>, out: Collection<V>, fcn: ArrayCallback<T, U, V, W>, thisArg?: ThisParameterType<ArrayCallback<T, U, V, W>> ): Collection<V>;
|
|
279
251
|
}
|
|
280
252
|
|
|
281
253
|
/**
|
|
@@ -288,8 +260,7 @@ interface Routine {
|
|
|
288
260
|
* - **v1**: element from first input array.
|
|
289
261
|
* - **v2**: element from second input array.
|
|
290
262
|
* - **idx**: element index.
|
|
291
|
-
* - **
|
|
292
|
-
* - **y**: second input array.
|
|
263
|
+
* - **arrays**: input arrays.
|
|
293
264
|
*
|
|
294
265
|
* @param x - first input array
|
|
295
266
|
* @param y - second input array
|
|
@@ -298,8 +269,8 @@ interface Routine {
|
|
|
298
269
|
* @returns output array
|
|
299
270
|
*
|
|
300
271
|
* @example
|
|
301
|
-
* var naryFunction = require(
|
|
302
|
-
* var add = require(
|
|
272
|
+
* var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
273
|
+
* var add = require( '@stdlib/math-base-ops-add' );
|
|
303
274
|
*
|
|
304
275
|
* var x = [ 1, 2, 3, 4, 5, 6 ];
|
|
305
276
|
* var y = [ 1, 1, 1, 1, 1, 1 ];
|
|
@@ -308,9 +279,9 @@ interface Routine {
|
|
|
308
279
|
* // returns [ 2, 3, 4, 5, 6, 7 ]
|
|
309
280
|
*
|
|
310
281
|
* @example
|
|
311
|
-
* var naryFunction = require(
|
|
312
|
-
* var add = require(
|
|
313
|
-
* var array = require(
|
|
282
|
+
* var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
283
|
+
* var add = require( '@stdlib/math-base-ops-add' );
|
|
284
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
314
285
|
*
|
|
315
286
|
* var opts = {
|
|
316
287
|
* 'dtype': 'generic'
|
|
@@ -325,8 +296,8 @@ interface Routine {
|
|
|
325
296
|
* // returns [ 2, 3, 4, 5, 6, 7 ]
|
|
326
297
|
*
|
|
327
298
|
* @example
|
|
328
|
-
* var naryFunction = require(
|
|
329
|
-
* var add = require(
|
|
299
|
+
* var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
300
|
+
* var add = require( '@stdlib/math-base-ops-add' );
|
|
330
301
|
*
|
|
331
302
|
* var x = [ 1, 2, 3, 4, 5, 6 ];
|
|
332
303
|
* var y = [ 1, 1, 1, 1, 1, 1 ];
|
|
@@ -338,9 +309,9 @@ interface Routine {
|
|
|
338
309
|
* // => [ 2, 3, 4, 5, 6, 7 ]
|
|
339
310
|
*
|
|
340
311
|
* @example
|
|
341
|
-
* var naryFunction = require(
|
|
342
|
-
* var add = require(
|
|
343
|
-
* var array = require(
|
|
312
|
+
* var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
313
|
+
* var add = require( '@stdlib/math-base-ops-add' );
|
|
314
|
+
* var array = require( '@stdlib/ndarray-array' );
|
|
344
315
|
*
|
|
345
316
|
* var opts = {
|
|
346
317
|
* 'dtype': 'generic',
|
package/lib/array.js
CHANGED
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
* @private
|
|
27
27
|
* @param {Object} x - object containing data for the first input array
|
|
28
28
|
* @param {ArrayLikeObject} x.data - array data
|
|
29
|
-
* @param {Function} x.
|
|
29
|
+
* @param {Array<Function>} x.accessors - array element accessors
|
|
30
30
|
* @param {Object} y - object containing data for the second input array
|
|
31
31
|
* @param {ArrayLikeObject} y.data - array data
|
|
32
|
-
* @param {Function} y.
|
|
32
|
+
* @param {Array<Function>} y.accessors - array element accessors
|
|
33
33
|
* @param {Object} z - object containing output array data
|
|
34
34
|
* @param {ArrayLikeObject} z.data - array data
|
|
35
|
-
* @param {Function} z.
|
|
35
|
+
* @param {Array<Function>} z.accessors - array element accessors
|
|
36
36
|
* @param {Function} fcn - function to apply
|
|
37
37
|
* @param {*} thisArg - function execution context
|
|
38
38
|
* @returns {void}
|
|
@@ -53,15 +53,15 @@
|
|
|
53
53
|
* // Create the input and output array objects:
|
|
54
54
|
* var x = {
|
|
55
55
|
* 'data': [ 1, 2, 3, 4, 5, 6 ],
|
|
56
|
-
* '
|
|
56
|
+
* 'accessors': [ getter, setter ]
|
|
57
57
|
* };
|
|
58
58
|
* var y = {
|
|
59
59
|
* 'data': [ 1, 1, 1, 1, 1, 1 ],
|
|
60
|
-
* '
|
|
60
|
+
* 'accessors': [ getter, setter ]
|
|
61
61
|
* };
|
|
62
62
|
* var z = {
|
|
63
63
|
* 'data': [ 0, 0, 0, 0, 0, 0 ],
|
|
64
|
-
* '
|
|
64
|
+
* 'accessors': [ getter, setter ]
|
|
65
65
|
* };
|
|
66
66
|
*
|
|
67
67
|
* map2Right( x, y, z, naryFunction( add, 2 ) );
|
|
@@ -84,13 +84,13 @@ function map2Right( x, y, z, fcn, thisArg ) {
|
|
|
84
84
|
zbuf = z.data;
|
|
85
85
|
|
|
86
86
|
// Cache accessors:
|
|
87
|
-
xget = x.
|
|
88
|
-
yget = y.
|
|
89
|
-
zset = z.
|
|
87
|
+
xget = x.accessors[ 0 ];
|
|
88
|
+
yget = y.accessors[ 0 ];
|
|
89
|
+
zset = z.accessors[ 1 ];
|
|
90
90
|
|
|
91
91
|
// Iterate over the elements...
|
|
92
92
|
for ( i = xbuf.length-1; i >= 0; i-- ) {
|
|
93
|
-
zset( zbuf, i, fcn.call( thisArg, xget( xbuf, i ), yget( ybuf, i ), i, xbuf, ybuf ) ); // eslint-disable-line max-len
|
|
93
|
+
zset( zbuf, i, fcn.call( thisArg, xget( xbuf, i ), yget( ybuf, i ), i, [ xbuf, ybuf ] ) ); // eslint-disable-line max-len
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
package/lib/assign.js
CHANGED
|
@@ -27,6 +27,7 @@ var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );
|
|
|
27
27
|
var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
28
28
|
var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );
|
|
29
29
|
var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );
|
|
30
|
+
var format = require( '@stdlib/string-format' );
|
|
30
31
|
var ndarrayFcn = require( './ndarray.js' );
|
|
31
32
|
var arrayFcn = require( './array.js' );
|
|
32
33
|
|
|
@@ -43,8 +44,7 @@ var arrayFcn = require( './array.js' );
|
|
|
43
44
|
* - **v1**: element from first input array.
|
|
44
45
|
* - **v2**: element from second input array.
|
|
45
46
|
* - **idx**: element index.
|
|
46
|
-
* - **
|
|
47
|
-
* - **y**: second input array.
|
|
47
|
+
* - **arrays**: input arrays.
|
|
48
48
|
*
|
|
49
49
|
* @param {(ArrayLikeObject|ndarray)} x - first input array
|
|
50
50
|
* @param {(ArrayLikeObject|ndarray)} y - second input array
|
|
@@ -99,17 +99,17 @@ function map2Right( x, y, out, fcn, thisArg ) {
|
|
|
99
99
|
var tmp;
|
|
100
100
|
var sh;
|
|
101
101
|
if ( !isFunction( fcn ) ) {
|
|
102
|
-
throw new TypeError( 'invalid argument. Fourth argument must be a function. Value:
|
|
102
|
+
throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', fcn ) );
|
|
103
103
|
}
|
|
104
104
|
isxnd = isndarrayLike( x );
|
|
105
105
|
isynd = isndarrayLike( y );
|
|
106
106
|
isznd = isndarrayLike( out );
|
|
107
107
|
if ( isxnd ) { // note: assertion order matters here, as an ndarray-like object is also array-like
|
|
108
108
|
if ( !isynd ) {
|
|
109
|
-
throw new TypeError( 'invalid argument. If the first input array is an ndarray, the second input array must also be an ndarray. Value:
|
|
109
|
+
throw new TypeError( format( 'invalid argument. If the first input array is an ndarray, the second input array must also be an ndarray. Value: `%s`.', y ) );
|
|
110
110
|
}
|
|
111
111
|
if ( !isznd ) {
|
|
112
|
-
throw new TypeError( 'invalid argument. If the input arrays are ndarrays, the output array must also be an ndarray. Value:
|
|
112
|
+
throw new TypeError( format( 'invalid argument. If the input arrays are ndarrays, the output array must also be an ndarray. Value: `%s`.', out ) );
|
|
113
113
|
}
|
|
114
114
|
if ( isReadOnly( out ) ) {
|
|
115
115
|
throw new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );
|
|
@@ -131,18 +131,18 @@ function map2Right( x, y, out, fcn, thisArg ) {
|
|
|
131
131
|
}
|
|
132
132
|
if ( isArrayLikeObject( x ) ) {
|
|
133
133
|
if ( isynd || !isArrayLikeObject( y ) ) {
|
|
134
|
-
throw new TypeError( 'invalid argument. If the first input array is an array-like object, the second input array must also be an array-like object. Value:
|
|
134
|
+
throw new TypeError( format( 'invalid argument. If the first input array is an array-like object, the second input array must also be an array-like object. Value: `%s`.', y ) );
|
|
135
135
|
}
|
|
136
136
|
if ( isznd || !isArrayLikeObject( out ) ) {
|
|
137
|
-
throw new TypeError( 'invalid argument. If the input arrays are array-like objects, the output array must also be an array-like object. Value:
|
|
137
|
+
throw new TypeError( format( 'invalid argument. If the input arrays are array-like objects, the output array must also be an array-like object. Value: `%s`.', out ) );
|
|
138
138
|
}
|
|
139
139
|
if ( x.length !== y.length || y.length !== out.length ) {
|
|
140
|
-
throw new RangeError( 'invalid arguments. Input and output arrays must have the same
|
|
140
|
+
throw new RangeError( 'invalid arguments. Input and output arrays must have the same length.' );
|
|
141
141
|
}
|
|
142
142
|
arrayFcn( arraylike2object( x ), arraylike2object( y ), arraylike2object( out ), fcn, thisArg ); // eslint-disable-line max-len
|
|
143
143
|
return out;
|
|
144
144
|
}
|
|
145
|
-
throw new TypeError( 'invalid argument. First argument must be an array-like object or an ndarray. Value:
|
|
145
|
+
throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', x ) );
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
|
package/lib/main.js
CHANGED
|
@@ -29,6 +29,7 @@ var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
|
29
29
|
var ndzeros = require( '@stdlib/ndarray-zeros' );
|
|
30
30
|
var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );
|
|
31
31
|
var broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );
|
|
32
|
+
var format = require( '@stdlib/string-format' );
|
|
32
33
|
var ndarrayFcn = require( './ndarray.js' );
|
|
33
34
|
var arrayFcn = require( './array.js' );
|
|
34
35
|
|
|
@@ -45,8 +46,7 @@ var arrayFcn = require( './array.js' );
|
|
|
45
46
|
* - **v1**: element from first input array.
|
|
46
47
|
* - **v2**: element from second input array.
|
|
47
48
|
* - **idx**: element index.
|
|
48
|
-
* - **
|
|
49
|
-
* - **y**: second input array.
|
|
49
|
+
* - **arrays**: input arrays.
|
|
50
50
|
*
|
|
51
51
|
* @param {(ArrayLikeObject|ndarray)} x - first input array
|
|
52
52
|
* @param {(ArrayLikeObject|ndarray)} y - second input array
|
|
@@ -95,13 +95,13 @@ function map2Right( x, y, fcn, thisArg ) {
|
|
|
95
95
|
var sh;
|
|
96
96
|
|
|
97
97
|
if ( !isFunction( fcn ) ) {
|
|
98
|
-
throw new TypeError( 'invalid argument. Second argument must be a function. Value:
|
|
98
|
+
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );
|
|
99
99
|
}
|
|
100
100
|
isxnd = isndarrayLike( x );
|
|
101
101
|
isynd = isndarrayLike( y );
|
|
102
102
|
if ( isxnd ) { // note: assertion order matters here, as an ndarray-like object is also array-like
|
|
103
103
|
if ( !isynd ) {
|
|
104
|
-
throw new TypeError( 'invalid argument. If the first input array is an ndarray, the second input array must also be an ndarray. Value:
|
|
104
|
+
throw new TypeError( format( 'invalid argument. If the first input array is an ndarray, the second input array must also be an ndarray. Value: `%s`.', y ) );
|
|
105
105
|
}
|
|
106
106
|
// Broadcast `x` and `y` to a common shape:
|
|
107
107
|
sh = broadcastShapes( [ x.shape, y.shape ] );
|
|
@@ -129,16 +129,16 @@ function map2Right( x, y, fcn, thisArg ) {
|
|
|
129
129
|
}
|
|
130
130
|
if ( isArrayLikeObject( x ) ) {
|
|
131
131
|
if ( isynd || !isArrayLikeObject( y ) ) {
|
|
132
|
-
throw new TypeError( 'invalid argument. If the first input array is an array-like object, the second input array must also be an array-like object. Value:
|
|
132
|
+
throw new TypeError( format( 'invalid argument. If the first input array is an array-like object, the second input array must also be an array-like object. Value: `%s`.', y ) );
|
|
133
133
|
}
|
|
134
134
|
if ( y.length !== x.length ) {
|
|
135
|
-
throw new RangeError( 'invalid arguments. Input arrays must have the same
|
|
135
|
+
throw new RangeError( 'invalid arguments. Input arrays must have the same length.' );
|
|
136
136
|
}
|
|
137
137
|
out = zeros( x.length );
|
|
138
138
|
arrayFcn( arraylike2object( x ), arraylike2object( y ), arraylike2object( out ), fcn, thisArg ); // eslint-disable-line max-len
|
|
139
139
|
return out;
|
|
140
140
|
}
|
|
141
|
-
throw new TypeError( 'invalid argument. First argument must be an array-like object or an ndarray. Value:
|
|
141
|
+
throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', x ) );
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
|
package/lib/ndarray.js
CHANGED
|
@@ -43,7 +43,7 @@ var MODE = 'throw';
|
|
|
43
43
|
* @param {IntegerArray} x.strides - stride lengths
|
|
44
44
|
* @param {NonNegativeInteger} x.offset - index offset
|
|
45
45
|
* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)
|
|
46
|
-
* @param {Function} x.
|
|
46
|
+
* @param {Array<Function>} x.accessors - accessors for accessing data buffer elements
|
|
47
47
|
* @param {Object} y - object containing meta data for the second input ndarray
|
|
48
48
|
* @param {string} y.ref - reference to original input ndarray-like object
|
|
49
49
|
* @param {string} y.dtype - data type
|
|
@@ -53,7 +53,7 @@ var MODE = 'throw';
|
|
|
53
53
|
* @param {IntegerArray} y.strides - stride lengths
|
|
54
54
|
* @param {NonNegativeInteger} y.offset - index offset
|
|
55
55
|
* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style)
|
|
56
|
-
* @param {Function} y.
|
|
56
|
+
* @param {Array<Function>} y.accessors - accessors for accessing data buffer elements
|
|
57
57
|
* @param {Object} z - object containing output ndarray meta data
|
|
58
58
|
* @param {string} z.dtype - data type
|
|
59
59
|
* @param {Collection} z.data - data buffer
|
|
@@ -62,7 +62,7 @@ var MODE = 'throw';
|
|
|
62
62
|
* @param {IntegerArray} z.strides - stride lengths
|
|
63
63
|
* @param {NonNegativeInteger} z.offset - index offset
|
|
64
64
|
* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style)
|
|
65
|
-
* @param {Function} z.
|
|
65
|
+
* @param {Array<Function>} z.accessors - accessors for accessing data buffer elements
|
|
66
66
|
* @param {Function} fcn - function to apply
|
|
67
67
|
* @param {*} thisArg - function execution context
|
|
68
68
|
* @returns {void}
|
|
@@ -112,7 +112,7 @@ var MODE = 'throw';
|
|
|
112
112
|
* 'strides': sx,
|
|
113
113
|
* 'offset': ox,
|
|
114
114
|
* 'order': 'row-major',
|
|
115
|
-
* '
|
|
115
|
+
* 'accessors': [ getter, setter ]
|
|
116
116
|
* };
|
|
117
117
|
* x.ref = x;
|
|
118
118
|
*
|
|
@@ -125,7 +125,7 @@ var MODE = 'throw';
|
|
|
125
125
|
* 'strides': sy,
|
|
126
126
|
* 'offset': ox,
|
|
127
127
|
* 'order': 'row-major',
|
|
128
|
-
* '
|
|
128
|
+
* 'accessors': [ getter, setter ]
|
|
129
129
|
* };
|
|
130
130
|
* y.ref = y;
|
|
131
131
|
*
|
|
@@ -138,7 +138,7 @@ var MODE = 'throw';
|
|
|
138
138
|
* 'strides': sz,
|
|
139
139
|
* 'offset': oz,
|
|
140
140
|
* 'order': 'row-major',
|
|
141
|
-
* '
|
|
141
|
+
* 'accessors': [ getter, setter ]
|
|
142
142
|
* };
|
|
143
143
|
*
|
|
144
144
|
* // Apply the function:
|
|
@@ -208,9 +208,9 @@ function map2Right( x, y, z, fcn, thisArg ) {
|
|
|
208
208
|
ordz = z.order;
|
|
209
209
|
|
|
210
210
|
// Cache accessors:
|
|
211
|
-
xget = x.
|
|
212
|
-
yget = y.
|
|
213
|
-
zset = z.
|
|
211
|
+
xget = x.accessors[ 0 ];
|
|
212
|
+
yget = y.accessors[ 0 ];
|
|
213
|
+
zset = z.accessors[ 1 ];
|
|
214
214
|
|
|
215
215
|
// Cache references to the original input arrays:
|
|
216
216
|
xref = x.ref;
|
|
@@ -218,7 +218,7 @@ function map2Right( x, y, z, fcn, thisArg ) {
|
|
|
218
218
|
|
|
219
219
|
// Check for a zero-dimensional array...
|
|
220
220
|
if ( shx.length === 0 && shy.length === 0 ) {
|
|
221
|
-
zset( zbuf, oz, fcn.call( thisArg, xget( xbuf, ox ), yget( ybuf, oy ), 0, xref, yref ) ); // eslint-disable-line max-len
|
|
221
|
+
zset( zbuf, oz, fcn.call( thisArg, xget( xbuf, ox ), yget( ybuf, oy ), 0, [ xref, yref ] ) ); // eslint-disable-line max-len
|
|
222
222
|
return;
|
|
223
223
|
}
|
|
224
224
|
// Iterate over the arrays based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...
|
|
@@ -226,7 +226,7 @@ function map2Right( x, y, z, fcn, thisArg ) {
|
|
|
226
226
|
ix = vind2bind( shx, sx, ox, ordx, i, MODE );
|
|
227
227
|
iy = vind2bind( shy, sy, oy, ordy, i, MODE );
|
|
228
228
|
iz = vind2bind( shz, sz, oz, ordz, i, MODE );
|
|
229
|
-
zset( zbuf, iz, fcn.call( thisArg, xget( xbuf, ix ), yget( ybuf, iy ), i, xref, yref ) ); // eslint-disable-line max-len
|
|
229
|
+
zset( zbuf, iz, fcn.call( thisArg, xget( xbuf, ix ), yget( ybuf, iy ), i, [ xref, yref ] ) ); // eslint-disable-line max-len
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/utils-map2-right",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Apply a function to elements in two input arrays while iterating from right to left and assign the results to an output array.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -37,39 +37,42 @@
|
|
|
37
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@stdlib/array-base-arraylike2object": "^0.0
|
|
41
|
-
"@stdlib/array-base-zeros": "^0.0
|
|
42
|
-
"@stdlib/assert-is-array-like-object": "^0.0
|
|
43
|
-
"@stdlib/assert-is-function": "^0.0
|
|
44
|
-
"@stdlib/assert-is-ndarray-like": "^0.0
|
|
45
|
-
"@stdlib/ndarray-base-assert-is-read-only": "^0.0
|
|
46
|
-
"@stdlib/ndarray-base-broadcast-shapes": "^0.0
|
|
47
|
-
"@stdlib/ndarray-base-maybe-broadcast-array": "^0.0
|
|
48
|
-
"@stdlib/ndarray-base-ndarraylike2object": "^0.0
|
|
49
|
-
"@stdlib/ndarray-base-vind2bind": "^0.0
|
|
50
|
-
"@stdlib/ndarray-zeros": "^0.0
|
|
51
|
-
"@stdlib/
|
|
52
|
-
"@stdlib/
|
|
40
|
+
"@stdlib/array-base-arraylike2object": "^0.2.0",
|
|
41
|
+
"@stdlib/array-base-zeros": "^0.2.0",
|
|
42
|
+
"@stdlib/assert-is-array-like-object": "^0.2.0",
|
|
43
|
+
"@stdlib/assert-is-function": "^0.2.0",
|
|
44
|
+
"@stdlib/assert-is-ndarray-like": "^0.2.0",
|
|
45
|
+
"@stdlib/ndarray-base-assert-is-read-only": "^0.2.0",
|
|
46
|
+
"@stdlib/ndarray-base-broadcast-shapes": "^0.2.0",
|
|
47
|
+
"@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.0",
|
|
48
|
+
"@stdlib/ndarray-base-ndarraylike2object": "^0.2.0",
|
|
49
|
+
"@stdlib/ndarray-base-vind2bind": "^0.2.0",
|
|
50
|
+
"@stdlib/ndarray-zeros": "^0.2.0",
|
|
51
|
+
"@stdlib/string-format": "^0.2.0",
|
|
52
|
+
"@stdlib/types": "^0.3.1",
|
|
53
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0",
|
|
54
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.2.0"
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
55
|
-
"@stdlib/array-base-filled": "^0.0
|
|
56
|
-
"@stdlib/array-complex64": "^0.0
|
|
57
|
-
"@stdlib/array-filled-by": "^0.0
|
|
58
|
-
"@stdlib/array-float64": "^0.0
|
|
59
|
-
"@stdlib/assert-is-array": "^0.0
|
|
60
|
-
"@stdlib/
|
|
61
|
-
"@stdlib/complex-
|
|
62
|
-
"@stdlib/
|
|
63
|
-
"@stdlib/math-base-ops-
|
|
64
|
-
"@stdlib/math-base-
|
|
65
|
-
"@stdlib/
|
|
66
|
-
"@stdlib/ndarray-
|
|
67
|
-
"@stdlib/
|
|
68
|
-
"@stdlib/
|
|
69
|
-
"@stdlib/utils-nary-function": "^0.0.x",
|
|
57
|
+
"@stdlib/array-base-filled": "^0.2.0",
|
|
58
|
+
"@stdlib/array-complex64": "^0.1.0",
|
|
59
|
+
"@stdlib/array-filled-by": "^0.1.0",
|
|
60
|
+
"@stdlib/array-float64": "^0.2.0",
|
|
61
|
+
"@stdlib/assert-is-array": "^0.2.0",
|
|
62
|
+
"@stdlib/complex-imagf": "^0.2.0",
|
|
63
|
+
"@stdlib/complex-realf": "^0.2.0",
|
|
64
|
+
"@stdlib/math-base-ops-add": "^0.2.0",
|
|
65
|
+
"@stdlib/math-base-ops-caddf": "^0.2.0",
|
|
66
|
+
"@stdlib/math-base-special-pow": "^0.2.0",
|
|
67
|
+
"@stdlib/ndarray-array": "^0.1.0",
|
|
68
|
+
"@stdlib/ndarray-ctor": "^0.1.0",
|
|
69
|
+
"@stdlib/random-base-discrete-uniform": "^0.1.0",
|
|
70
|
+
"@stdlib/utils-nary-function": "^0.2.0",
|
|
70
71
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
71
72
|
"istanbul": "^0.4.1",
|
|
72
|
-
"tap-
|
|
73
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",
|
|
74
|
+
"@stdlib/bench-harness": "^0.2.0",
|
|
75
|
+
"@stdlib/bench": "^0.3.1"
|
|
73
76
|
},
|
|
74
77
|
"engines": {
|
|
75
78
|
"node": ">=0.10.0",
|
|
@@ -113,7 +116,7 @@
|
|
|
113
116
|
"binary"
|
|
114
117
|
],
|
|
115
118
|
"funding": {
|
|
116
|
-
"type": "
|
|
117
|
-
"url": "https://
|
|
119
|
+
"type": "opencollective",
|
|
120
|
+
"url": "https://opencollective.com/stdlib"
|
|
118
121
|
}
|
|
119
122
|
}
|