@stdlib/utils-map 0.2.0 → 0.2.2
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/NOTICE +1 -1
- package/README.md +8 -8
- package/dist/index.js +18 -10
- package/dist/index.js.map +1 -1
- package/lib/ndarray.js +3 -3
- package/package.json +17 -46
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -220,9 +220,9 @@ The applied function is provided the same arguments as with [`map`](#fcn-map).
|
|
|
220
220
|
|
|
221
221
|
```javascript
|
|
222
222
|
var Complex64Array = require( '@stdlib/array-complex64' );
|
|
223
|
-
var Complex64 = require( '@stdlib/complex-float32' );
|
|
224
|
-
var realf = require( '@stdlib/complex-
|
|
225
|
-
var imagf = require( '@stdlib/complex-
|
|
223
|
+
var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
224
|
+
var realf = require( '@stdlib/complex-float32-real' );
|
|
225
|
+
var imagf = require( '@stdlib/complex-float32-imag' );
|
|
226
226
|
|
|
227
227
|
function scale( z ) {
|
|
228
228
|
return new Complex64( realf(z)*10.0, imagf(z)*10.0 );
|
|
@@ -343,7 +343,7 @@ See [LICENSE][stdlib-license].
|
|
|
343
343
|
|
|
344
344
|
## Copyright
|
|
345
345
|
|
|
346
|
-
Copyright © 2016-
|
|
346
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
347
347
|
|
|
348
348
|
</section>
|
|
349
349
|
|
|
@@ -356,8 +356,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
356
356
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/utils-map.svg
|
|
357
357
|
[npm-url]: https://npmjs.org/package/@stdlib/utils-map
|
|
358
358
|
|
|
359
|
-
[test-image]: https://github.com/stdlib-js/utils-map/actions/workflows/test.yml/badge.svg?branch=v0.2.
|
|
360
|
-
[test-url]: https://github.com/stdlib-js/utils-map/actions/workflows/test.yml?query=branch:v0.2.
|
|
359
|
+
[test-image]: https://github.com/stdlib-js/utils-map/actions/workflows/test.yml/badge.svg?branch=v0.2.2
|
|
360
|
+
[test-url]: https://github.com/stdlib-js/utils-map/actions/workflows/test.yml?query=branch:v0.2.2
|
|
361
361
|
|
|
362
362
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/utils-map/main.svg
|
|
363
363
|
[coverage-url]: https://codecov.io/github/stdlib-js/utils-map?branch=main
|
|
@@ -369,8 +369,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
369
369
|
|
|
370
370
|
-->
|
|
371
371
|
|
|
372
|
-
[chat-image]: https://img.shields.io/
|
|
373
|
-
[chat-url]: https://
|
|
372
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
373
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
374
374
|
|
|
375
375
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
376
376
|
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
"use strict";var d=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var b=d(function(sr,O){
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";var d=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var b=d(function(sr,O){"use strict";var T=require("@stdlib/ndarray-base-vind2bind"),V="throw";function J(r,e,i,a){var t,n,v,o,s,y,c,m,f,w,k,j,h,p,E,F,u;if(s=r.length,f=r.shape,w=e.shape,t=r.data,n=e.data,k=r.strides,j=e.strides,h=r.offset,p=e.offset,v=r.order,o=e.order,y=r.accessors[0],c=e.accessors[1],m=r.ref,f.length===0){c(n,p,i.call(a,y(t,h),0,m));return}for(u=0;u<s;u++)E=T(f,k,h,v,u,V),F=T(w,j,p,o,u,V),c(n,F,i.call(a,y(t,E),u,m))}O.exports=J});var q=d(function(ur,x){"use strict";function K(r,e,i,a){var t,n,v,o,s;for(t=r.data,n=e.data,v=r.accessors[0],o=e.accessors[1],s=0;s<t.length;s++)o(n,s,i.call(a,v(t,s),s,t))}x.exports=K});var C=d(function(vr,z){"use strict";var N=require("@stdlib/assert-is-array-like-object"),P=require("@stdlib/assert-is-ndarray-like"),Q=require("@stdlib/assert-is-function"),U=require("@stdlib/array-base-zeros"),L=require("@stdlib/ndarray-base-ndarraylike2object"),I=require("@stdlib/array-base-arraylike2object"),W=require("@stdlib/ndarray-zeros"),R=require("@stdlib/string-format"),X=b(),Y=q();function Z(r,e,i){var a;if(!Q(e))throw new TypeError(R("invalid argument. Second argument must be a function. Value: `%s`.",e));if(P(r))return r=L(r),a=W(r.shape,{dtype:"generic",order:r.order}),X(r,L(a),e,i),a;if(N(r))return a=U(r.length),Y(I(r),I(a),e,i),a;throw new TypeError(R("invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.",r))}z.exports=Z});var G=d(function(or,B){"use strict";var D=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-ndarray-like"),_=require("@stdlib/assert-is-function"),M=require("@stdlib/ndarray-base-ndarraylike2object"),S=require("@stdlib/array-base-arraylike2object"),$=require("@stdlib/ndarray-base-maybe-broadcast-array"),A=require("@stdlib/ndarray-base-assert-is-read-only"),l=require("@stdlib/string-format"),rr=b(),er=q();function ar(r,e,i,a){var t,n;if(!_(i))throw new TypeError(l("invalid argument. Third argument must be a function. Value: `%s`.",i));if(g(r)){if(!g(e))throw new TypeError(l("invalid argument. If the input array is an ndarray, the output array must also be an ndarray. Value: `%s`.",e));if(A(e))throw new Error("invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.");return e=M(e),n=e.shape,t=M($(r,n)),t.ref=r,r=t,rr(r,e,i,a),e.ref}if(D(r)){if(!D(e)||g(e))throw new TypeError(l("invalid argument. If the input array is an array-like object, the output array must also be an array-like object. Value: `%s`.",e));if(r.length!==e.length)throw new RangeError("invalid arguments. Input and output arrays must have the same length.");return er(S(r),S(e),i,a),e}throw new TypeError(l("invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.",r))}B.exports=ar});var ir=require("@stdlib/utils-define-nonenumerable-read-only-property"),H=C(),tr=G();ir(H,"assign",tr);module.exports=H;
|
|
2
|
+
/**
|
|
3
|
+
* @license Apache-2.0
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2021 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
|
+
*/
|
|
11
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/assign.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Applies a function to each element in an ndarray and assigns the result to an element in an output ndarray.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array<Function>} x.accessors - accessors for accessing data buffer elements\n* @param {Object} y - object containing output ndarray meta data\n* @param {string} y.dtype - data type\n* @param {Collection} y.data - data buffer\n* @param {NonNegativeInteger} y.length - number of elements\n* @param {NonNegativeIntegerArray} y.shape - dimensions\n* @param {IntegerArray} y.strides - stride lengths\n* @param {NonNegativeInteger} y.offset - index offset\n* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array<Function>} y.accessors - accessors for accessing data buffer elements\n* @param {Function} fcn - function to apply\n* @param {*} thisArg - function execution context\n* @returns {void}\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* function scale( z ) {\n* return new Complex64( realf(z)*10.0, imagf(z)*10.0 );\n* }\n*\n* // Create data buffers:\n* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n* var ybuf = new Complex64Array( 4 );\n*\n* // Define the shape of the input and output arrays:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n* var sy = [ 2, 1 ];\n*\n* // Define the index offsets:\n* var ox = 0;\n* var oy = 0;\n*\n* // Define getters and setters:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* function setter( buf, idx, value ) {\n* buf.set( value, idx );\n* }\n*\n* // Create the input and output ndarray-like objects:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter, setter ]\n* };\n* x.ref = x;\n*\n* var y = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': ybuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sy,\n* 'offset': oy,\n* 'order': 'row-major',\n* 'accessors': [ getter, setter ]\n* };\n*\n* // Apply the unary function:\n* map( x, y, naryFunction( scale, 1 ) );\n*\n* var v = y.data.get( 0 );\n*\n* var re = realf( v );\n* // returns 10.0\n*\n* var im = imagf( v );\n* // returns 20.0\n*/\nfunction map( x, y, fcn, thisArg ) {\n\tvar xbuf;\n\tvar ybuf;\n\tvar ordx;\n\tvar ordy;\n\tvar len;\n\tvar get;\n\tvar set;\n\tvar ref;\n\tvar shx;\n\tvar shy;\n\tvar sx;\n\tvar sy;\n\tvar ox;\n\tvar oy;\n\tvar ix;\n\tvar iy;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\tshy = y.shape;\n\n\t// Cache references to the input and output ndarray data buffers:\n\txbuf = x.data;\n\tybuf = y.data;\n\n\t// Cache references to the respective stride arrays:\n\tsx = x.strides;\n\tsy = y.strides;\n\n\t// Cache the indices of the first indexed elements in the respective ndarrays:\n\tox = x.offset;\n\toy = y.offset;\n\n\t// Cache the respective array orders:\n\tordx = x.order;\n\tordy = y.order;\n\n\t// Cache accessors:\n\tget = x.accessors[ 0 ];\n\tset = y.accessors[ 1 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\tset( ybuf, oy, fcn.call( thisArg, get( xbuf, ox ), 0, ref ) );\n\t\treturn;\n\t}\n\t// Iterate over each element 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)...\n\tfor ( i = 0; i < len; i++ ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tiy = vind2bind( shy, sy, oy, ordy, i, MODE );\n\t\tset( ybuf, iy, fcn.call( thisArg, get( xbuf, ix ), i, ref ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = map;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 each element in an array and assigns the result to an element in an output array.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array<Function>} x.accessors - input array accessors\n* @param {Object} y - object containing output array data\n* @param {ArrayLikeObject} y.data - output array data\n* @param {Array<Function>} y.accessors - output array accessors\n* @param {Function} fcn - function to apply\n* @param {*} thisArg - function execution context\n* @returns {void}\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n*\n* // Define getters and setters:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* function setter( buf, idx, value ) {\n* buf[ idx ] = value;\n* }\n*\n* // Create the input and output array objects:\n* var x = {\n* 'data': [ -1, -2, -3, -4, -5, -6 ],\n* 'accessors': [ getter, setter ]\n* };\n* var y = {\n* 'data': [ 0, 0, 0, 0, 0, 0 ],\n* 'accessors': [ getter, setter ]\n* };\n*\n* map( x, y, naryFunction( abs, 1 ) );\n*\n* var data = y.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*/\nfunction map( x, y, fcn, thisArg ) {\n\tvar xbuf;\n\tvar ybuf;\n\tvar get;\n\tvar set;\n\tvar i;\n\n\t// Cache references to the input and output data:\n\txbuf = x.data;\n\tybuf = y.data;\n\n\t// Cache accessors:\n\tget = x.accessors[ 0 ];\n\tset = y.accessors[ 1 ];\n\n\t// Iterate over each element...\n\tfor ( i = 0; i < xbuf.length; i++ ) {\n\t\tset( ybuf, i, fcn.call( thisArg, get( xbuf, i ), i, xbuf ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = map;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar ndzeros = require( '@stdlib/ndarray-zeros' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Applies a function to each element in an array and assigns the result to an element in a new array.\n*\n* ## Notes\n*\n* - The applied function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {Function} fcn - function to apply\n* @param {*} [thisArg] - function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} second argument must be a function\n* @returns {(Array|ndarray)} output array\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n*\n* var arr = [ -1, -2, -3, -4, -5, -6 ];\n*\n* var out = map( arr, naryFunction( abs, 1 ) );\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = map( arr, naryFunction( abs, 1 ) );\n* // returns <ndarray>\n*\n* var data = out.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*/\nfunction map( arr, fcn, thisArg ) {\n\tvar out;\n\tif ( !isFunction( fcn ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\tarr = ndarraylike2object( arr );\n\t\tout = ndzeros( arr.shape, {\n\t\t\t'dtype': 'generic',\n\t\t\t'order': arr.order\n\t\t});\n\t\tndarrayFcn( arr, ndarraylike2object( out ), fcn, thisArg );\n\t\treturn out;\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\tout = zeros( arr.length );\n\t\tarrayFcn( arraylike2object( arr ), arraylike2object( out ), fcn, thisArg ); // eslint-disable-line max-len\n\t\treturn out;\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = map;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Applies a function to each element in an array and assigns the result to an element in an output array.\n*\n* ## Notes\n*\n* - The applied function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {(ArrayLikeObject|ndarray)} out - output array\n* @param {Function} fcn - function to apply\n* @param {*} [thisArg] - function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} second argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} input and output arrays must be either both array-like objects or both ndarrays\n* @throws {RangeError} input and output arrays must have the same length\n* @throws {Error} input and output ndarrays must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {(ArrayLikeObject|ndarray)} output array\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n*\n* var arr = [ -1, -2, -3, -4, -5, -6 ];\n* var out = [ 0, 0, 0, 0, 0, 0 ];\n*\n* map( arr, out, naryFunction( abs, 1 ) );\n*\n* console.log( out );\n* // => [ 1, 2, 3, 4, 5, 6 ]\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic',\n* 'shape': [ 2, 3 ]\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n* var out = array( opts );\n*\n* map( arr, out, naryFunction( abs, 1 ) );\n*\n* var data = out.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*/\nfunction map( arr, out, fcn, thisArg ) {\n\tvar tmp;\n\tvar sh;\n\tif ( !isFunction( fcn ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', fcn ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\tif ( !isndarrayLike( out ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. If the input array is an ndarray, the output array must also be an ndarray. Value: `%s`.', out ) );\n\t\t}\n\t\tif ( isReadOnly( out ) ) {\n\t\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t\t}\n\t\tout = ndarraylike2object( out );\n\t\tsh = out.shape;\n\n\t\ttmp = ndarraylike2object( broadcast( arr, sh ) );\n\t\ttmp.ref = arr;\n\t\tarr = tmp;\n\n\t\tndarrayFcn( arr, out, fcn, thisArg );\n\t\treturn out.ref;\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\tif ( !isArrayLikeObject( out ) || isndarrayLike( out ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. If the input array is an array-like object, the output array must also be an array-like object. Value: `%s`.', out ) );\n\t\t}\n\t\tif ( arr.length !== out.length ) {\n\t\t\tthrow new RangeError( 'invalid arguments. Input and output arrays must have the same length.' );\n\t\t}\n\t\tarrayFcn( arraylike2object( arr ), arraylike2object( out ), fcn, thisArg ); // eslint-disable-line max-len\n\t\treturn out;\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = map;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 each element in an array and assign the result to an element in an output array.\n*\n* @module @stdlib/utils-map\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var map = require( '@stdlib/utils-map' );\n*\n* var arr = [ -1, -2, -3, -4, -5, -6 ];\n*\n* var out = map( arr, naryFunction( abs, 1 ) );\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var map = require( '@stdlib/utils-map' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = map( arr, naryFunction( abs, 1 ) );\n* // returns <ndarray>\n*\n* var data = out.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var map = require( '@stdlib/utils-map' );\n*\n* var arr = [ -1, -2, -3, -4, -5, -6 ];\n* var out = [ 0, 0, 0, 0, 0, 0 ];\n*\n* map.assign( arr, out, naryFunction( abs, 1 ) );\n*\n* console.log( out );\n* // => [ 1, 2, 3, 4, 5, 6 ]\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var map = require( '@stdlib/utils-map' );\n*\n* var opts = {\n* 'dtype': 'generic',\n* 'shape': [ 2, 3 ]\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n* var out = array( opts );\n*\n* map.assign( arr, out, naryFunction( abs, 1 ) );\n*\n* var data = out.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\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"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Applies a function to each element in an ndarray and assigns the result to an element in an output ndarray.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array<Function>} x.accessors - accessors for accessing data buffer elements\n* @param {Object} y - object containing output ndarray meta data\n* @param {string} y.dtype - data type\n* @param {Collection} y.data - data buffer\n* @param {NonNegativeInteger} y.length - number of elements\n* @param {NonNegativeIntegerArray} y.shape - dimensions\n* @param {IntegerArray} y.strides - stride lengths\n* @param {NonNegativeInteger} y.offset - index offset\n* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array<Function>} y.accessors - accessors for accessing data buffer elements\n* @param {Function} fcn - function to apply\n* @param {*} thisArg - function execution context\n* @returns {void}\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32-ctor' );\n* var realf = require( '@stdlib/complex-float32-real' );\n* var imagf = require( '@stdlib/complex-float32-imag' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* function scale( z ) {\n* return new Complex64( realf(z)*10.0, imagf(z)*10.0 );\n* }\n*\n* // Create data buffers:\n* var xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n* var ybuf = new Complex64Array( 4 );\n*\n* // Define the shape of the input and output arrays:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n* var sy = [ 2, 1 ];\n*\n* // Define the index offsets:\n* var ox = 0;\n* var oy = 0;\n*\n* // Define getters and setters:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* function setter( buf, idx, value ) {\n* buf.set( value, idx );\n* }\n*\n* // Create the input and output ndarray-like objects:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter, setter ]\n* };\n* x.ref = x;\n*\n* var y = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': ybuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sy,\n* 'offset': oy,\n* 'order': 'row-major',\n* 'accessors': [ getter, setter ]\n* };\n*\n* // Apply the unary function:\n* map( x, y, naryFunction( scale, 1 ) );\n*\n* var v = y.data.get( 0 );\n*\n* var re = realf( v );\n* // returns 10.0\n*\n* var im = imagf( v );\n* // returns 20.0\n*/\nfunction map( x, y, fcn, thisArg ) {\n\tvar xbuf;\n\tvar ybuf;\n\tvar ordx;\n\tvar ordy;\n\tvar len;\n\tvar get;\n\tvar set;\n\tvar ref;\n\tvar shx;\n\tvar shy;\n\tvar sx;\n\tvar sy;\n\tvar ox;\n\tvar oy;\n\tvar ix;\n\tvar iy;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\tshy = y.shape;\n\n\t// Cache references to the input and output ndarray data buffers:\n\txbuf = x.data;\n\tybuf = y.data;\n\n\t// Cache references to the respective stride arrays:\n\tsx = x.strides;\n\tsy = y.strides;\n\n\t// Cache the indices of the first indexed elements in the respective ndarrays:\n\tox = x.offset;\n\toy = y.offset;\n\n\t// Cache the respective array orders:\n\tordx = x.order;\n\tordy = y.order;\n\n\t// Cache accessors:\n\tget = x.accessors[ 0 ];\n\tset = y.accessors[ 1 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\tset( ybuf, oy, fcn.call( thisArg, get( xbuf, ox ), 0, ref ) );\n\t\treturn;\n\t}\n\t// Iterate over each element 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)...\n\tfor ( i = 0; i < len; i++ ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tiy = vind2bind( shy, sy, oy, ordy, i, MODE );\n\t\tset( ybuf, iy, fcn.call( thisArg, get( xbuf, ix ), i, ref ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = map;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 each element in an array and assigns the result to an element in an output array.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array<Function>} x.accessors - input array accessors\n* @param {Object} y - object containing output array data\n* @param {ArrayLikeObject} y.data - output array data\n* @param {Array<Function>} y.accessors - output array accessors\n* @param {Function} fcn - function to apply\n* @param {*} thisArg - function execution context\n* @returns {void}\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n*\n* // Define getters and setters:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* function setter( buf, idx, value ) {\n* buf[ idx ] = value;\n* }\n*\n* // Create the input and output array objects:\n* var x = {\n* 'data': [ -1, -2, -3, -4, -5, -6 ],\n* 'accessors': [ getter, setter ]\n* };\n* var y = {\n* 'data': [ 0, 0, 0, 0, 0, 0 ],\n* 'accessors': [ getter, setter ]\n* };\n*\n* map( x, y, naryFunction( abs, 1 ) );\n*\n* var data = y.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*/\nfunction map( x, y, fcn, thisArg ) {\n\tvar xbuf;\n\tvar ybuf;\n\tvar get;\n\tvar set;\n\tvar i;\n\n\t// Cache references to the input and output data:\n\txbuf = x.data;\n\tybuf = y.data;\n\n\t// Cache accessors:\n\tget = x.accessors[ 0 ];\n\tset = y.accessors[ 1 ];\n\n\t// Iterate over each element...\n\tfor ( i = 0; i < xbuf.length; i++ ) {\n\t\tset( ybuf, i, fcn.call( thisArg, get( xbuf, i ), i, xbuf ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = map;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar ndzeros = require( '@stdlib/ndarray-zeros' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Applies a function to each element in an array and assigns the result to an element in a new array.\n*\n* ## Notes\n*\n* - The applied function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {Function} fcn - function to apply\n* @param {*} [thisArg] - function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} second argument must be a function\n* @returns {(Array|ndarray)} output array\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n*\n* var arr = [ -1, -2, -3, -4, -5, -6 ];\n*\n* var out = map( arr, naryFunction( abs, 1 ) );\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = map( arr, naryFunction( abs, 1 ) );\n* // returns <ndarray>\n*\n* var data = out.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*/\nfunction map( arr, fcn, thisArg ) {\n\tvar out;\n\tif ( !isFunction( fcn ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\tarr = ndarraylike2object( arr );\n\t\tout = ndzeros( arr.shape, {\n\t\t\t'dtype': 'generic',\n\t\t\t'order': arr.order\n\t\t});\n\t\tndarrayFcn( arr, ndarraylike2object( out ), fcn, thisArg );\n\t\treturn out;\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\tout = zeros( arr.length );\n\t\tarrayFcn( arraylike2object( arr ), arraylike2object( out ), fcn, thisArg ); // eslint-disable-line max-len\n\t\treturn out;\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = map;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar broadcast = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Applies a function to each element in an array and assigns the result to an element in an output array.\n*\n* ## Notes\n*\n* - The applied function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {(ArrayLikeObject|ndarray)} out - output array\n* @param {Function} fcn - function to apply\n* @param {*} [thisArg] - function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} second argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} input and output arrays must be either both array-like objects or both ndarrays\n* @throws {RangeError} input and output arrays must have the same length\n* @throws {Error} input and output ndarrays must be broadcast compatible\n* @throws {Error} cannot write to a read-only ndarray\n* @returns {(ArrayLikeObject|ndarray)} output array\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n*\n* var arr = [ -1, -2, -3, -4, -5, -6 ];\n* var out = [ 0, 0, 0, 0, 0, 0 ];\n*\n* map( arr, out, naryFunction( abs, 1 ) );\n*\n* console.log( out );\n* // => [ 1, 2, 3, 4, 5, 6 ]\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic',\n* 'shape': [ 2, 3 ]\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n* var out = array( opts );\n*\n* map( arr, out, naryFunction( abs, 1 ) );\n*\n* var data = out.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*/\nfunction map( arr, out, fcn, thisArg ) {\n\tvar tmp;\n\tvar sh;\n\tif ( !isFunction( fcn ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', fcn ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\tif ( !isndarrayLike( out ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. If the input array is an ndarray, the output array must also be an ndarray. Value: `%s`.', out ) );\n\t\t}\n\t\tif ( isReadOnly( out ) ) {\n\t\t\tthrow new Error( 'invalid argument. The output ndarray must be writable. Cannot write to a read-only ndarray.' );\n\t\t}\n\t\tout = ndarraylike2object( out );\n\t\tsh = out.shape;\n\n\t\ttmp = ndarraylike2object( broadcast( arr, sh ) );\n\t\ttmp.ref = arr;\n\t\tarr = tmp;\n\n\t\tndarrayFcn( arr, out, fcn, thisArg );\n\t\treturn out.ref;\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\tif ( !isArrayLikeObject( out ) || isndarrayLike( out ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. If the input array is an array-like object, the output array must also be an array-like object. Value: `%s`.', out ) );\n\t\t}\n\t\tif ( arr.length !== out.length ) {\n\t\t\tthrow new RangeError( 'invalid arguments. Input and output arrays must have the same length.' );\n\t\t}\n\t\tarrayFcn( arraylike2object( arr ), arraylike2object( out ), fcn, thisArg ); // eslint-disable-line max-len\n\t\treturn out;\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = map;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 each element in an array and assign the result to an element in an output array.\n*\n* @module @stdlib/utils-map\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var map = require( '@stdlib/utils-map' );\n*\n* var arr = [ -1, -2, -3, -4, -5, -6 ];\n*\n* var out = map( arr, naryFunction( abs, 1 ) );\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var map = require( '@stdlib/utils-map' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = map( arr, naryFunction( abs, 1 ) );\n* // returns <ndarray>\n*\n* var data = out.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var map = require( '@stdlib/utils-map' );\n*\n* var arr = [ -1, -2, -3, -4, -5, -6 ];\n* var out = [ 0, 0, 0, 0, 0, 0 ];\n*\n* map.assign( arr, out, naryFunction( abs, 1 ) );\n*\n* console.log( out );\n* // => [ 1, 2, 3, 4, 5, 6 ]\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var map = require( '@stdlib/utils-map' );\n*\n* var opts = {\n* 'dtype': 'generic',\n* 'shape': [ 2, 3 ]\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n* var out = array( opts );\n*\n* map.assign( arr, out, naryFunction( abs, 1 ) );\n*\n* var data = out.data;\n* // returns [ 1, 2, 3, 4, 5, 6 ]\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
5
|
"mappings": "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",
|
|
6
6
|
"names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "map", "x", "y", "fcn", "thisArg", "xbuf", "ybuf", "ordx", "ordy", "len", "get", "set", "ref", "shx", "shy", "sx", "sy", "ox", "oy", "ix", "iy", "i", "require_array", "__commonJSMin", "exports", "module", "map", "x", "y", "fcn", "thisArg", "xbuf", "ybuf", "get", "set", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "zeros", "ndarraylike2object", "arraylike2object", "ndzeros", "format", "ndarrayFcn", "arrayFcn", "map", "arr", "fcn", "thisArg", "out", "require_assign", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "broadcast", "isReadOnly", "format", "ndarrayFcn", "arrayFcn", "map", "arr", "out", "fcn", "thisArg", "tmp", "sh", "setReadOnly", "main", "assign"]
|
|
7
7
|
}
|
package/lib/ndarray.js
CHANGED
|
@@ -59,9 +59,9 @@ var MODE = 'throw';
|
|
|
59
59
|
*
|
|
60
60
|
* @example
|
|
61
61
|
* var Complex64Array = require( '@stdlib/array-complex64' );
|
|
62
|
-
* var Complex64 = require( '@stdlib/complex-float32' );
|
|
63
|
-
* var realf = require( '@stdlib/complex-
|
|
64
|
-
* var imagf = require( '@stdlib/complex-
|
|
62
|
+
* var Complex64 = require( '@stdlib/complex-float32-ctor' );
|
|
63
|
+
* var realf = require( '@stdlib/complex-float32-real' );
|
|
64
|
+
* var imagf = require( '@stdlib/complex-float32-imag' );
|
|
65
65
|
* var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
66
66
|
*
|
|
67
67
|
* function scale( z ) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/utils-map",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Apply a function to each element in an array and assign the result to an element in an output array.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -15,19 +15,12 @@
|
|
|
15
15
|
],
|
|
16
16
|
"main": "./lib",
|
|
17
17
|
"directories": {
|
|
18
|
-
"benchmark": "./benchmark",
|
|
19
18
|
"doc": "./docs",
|
|
20
|
-
"example": "./examples",
|
|
21
19
|
"lib": "./lib",
|
|
22
|
-
"
|
|
20
|
+
"dist": "./dist"
|
|
23
21
|
},
|
|
24
22
|
"types": "./docs/types",
|
|
25
|
-
"scripts": {
|
|
26
|
-
"test": "make test",
|
|
27
|
-
"test-cov": "make test-cov",
|
|
28
|
-
"examples": "make examples",
|
|
29
|
-
"benchmark": "make benchmark"
|
|
30
|
-
},
|
|
23
|
+
"scripts": {},
|
|
31
24
|
"homepage": "https://stdlib.io",
|
|
32
25
|
"repository": {
|
|
33
26
|
"type": "git",
|
|
@@ -37,43 +30,21 @@
|
|
|
37
30
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
31
|
},
|
|
39
32
|
"dependencies": {
|
|
40
|
-
"@stdlib/array-base-arraylike2object": "^0.2.
|
|
41
|
-
"@stdlib/array-base-zeros": "^0.2.
|
|
42
|
-
"@stdlib/assert-is-array-like-object": "^0.2.
|
|
43
|
-
"@stdlib/assert-is-function": "^0.2.
|
|
44
|
-
"@stdlib/assert-is-ndarray-like": "^0.2.
|
|
45
|
-
"@stdlib/ndarray-base-assert-is-read-only": "^0.2.
|
|
46
|
-
"@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.
|
|
47
|
-
"@stdlib/ndarray-base-ndarraylike2object": "^0.2.
|
|
48
|
-
"@stdlib/ndarray-base-vind2bind": "^0.2.
|
|
49
|
-
"@stdlib/ndarray-zeros": "^0.
|
|
50
|
-
"@stdlib/string-format": "^0.2.
|
|
51
|
-
"@stdlib/
|
|
52
|
-
"@stdlib/
|
|
53
|
-
"@stdlib/error-tools-fmtprodmsg": "^0.2.0"
|
|
54
|
-
},
|
|
55
|
-
"devDependencies": {
|
|
56
|
-
"@stdlib/array-base-filled": "^0.2.0",
|
|
57
|
-
"@stdlib/array-complex64": "^0.1.0",
|
|
58
|
-
"@stdlib/array-filled-by": "^0.1.0",
|
|
59
|
-
"@stdlib/array-float64": "^0.2.0",
|
|
60
|
-
"@stdlib/assert-is-array": "^0.2.0",
|
|
61
|
-
"@stdlib/complex-float32": "^0.2.0",
|
|
62
|
-
"@stdlib/complex-imagf": "^0.2.0",
|
|
63
|
-
"@stdlib/complex-realf": "^0.2.0",
|
|
64
|
-
"@stdlib/math-base-special-abs": "^0.2.0",
|
|
65
|
-
"@stdlib/math-base-special-abs2": "^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",
|
|
71
|
-
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
72
|
-
"istanbul": "^0.4.1",
|
|
73
|
-
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",
|
|
74
|
-
"@stdlib/bench-harness": "^0.2.0",
|
|
75
|
-
"@stdlib/bench": "^0.3.1"
|
|
33
|
+
"@stdlib/array-base-arraylike2object": "^0.2.2",
|
|
34
|
+
"@stdlib/array-base-zeros": "^0.2.3",
|
|
35
|
+
"@stdlib/assert-is-array-like-object": "^0.2.3",
|
|
36
|
+
"@stdlib/assert-is-function": "^0.2.3",
|
|
37
|
+
"@stdlib/assert-is-ndarray-like": "^0.2.2",
|
|
38
|
+
"@stdlib/ndarray-base-assert-is-read-only": "^0.2.3",
|
|
39
|
+
"@stdlib/ndarray-base-maybe-broadcast-array": "^0.2.5",
|
|
40
|
+
"@stdlib/ndarray-base-ndarraylike2object": "^0.2.3",
|
|
41
|
+
"@stdlib/ndarray-base-vind2bind": "^0.2.3",
|
|
42
|
+
"@stdlib/ndarray-zeros": "^0.3.0",
|
|
43
|
+
"@stdlib/string-format": "^0.2.3",
|
|
44
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3",
|
|
45
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.2.3"
|
|
76
46
|
},
|
|
47
|
+
"devDependencies": {},
|
|
77
48
|
"engines": {
|
|
78
49
|
"node": ">=0.10.0",
|
|
79
50
|
"npm": ">2.7.0"
|