@stdlib/utils-map-reduce 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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -158,10 +158,10 @@ var mean = out / ctx.count;
158
158
 
159
159
  ```javascript
160
160
  var Complex64Array = require( '@stdlib/array-complex64' );
161
- var Complex64 = require( '@stdlib/complex-float32' );
161
+ var Complex64 = require( '@stdlib/complex-float32-ctor' );
162
162
  var cceil = require( '@stdlib/math-base-special-cceil' );
163
- var realf = require( '@stdlib/complex-realf' );
164
- var imagf = require( '@stdlib/complex-imagf' );
163
+ var realf = require( '@stdlib/complex-float32-real' );
164
+ var imagf = require( '@stdlib/complex-float32-imag' );
165
165
 
166
166
  function sum( acc, z ) {
167
167
  var re1 = realf( acc );
@@ -203,7 +203,7 @@ var mean = out / ctx.count;
203
203
  var filledarrayBy = require( '@stdlib/array-filled-by' );
204
204
  var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory;
205
205
  var naryFunction = require( '@stdlib/utils-nary-function' );
206
- var add = require( '@stdlib/math-base-ops-add' );
206
+ var add = require( '@stdlib/number-float64-base-add' );
207
207
  var abs = require( '@stdlib/math-base-special-abs' );
208
208
  var array = require( '@stdlib/ndarray-array' );
209
209
  var mapReduce = require( '@stdlib/utils-map-reduce' );
@@ -288,7 +288,7 @@ See [LICENSE][stdlib-license].
288
288
 
289
289
  ## Copyright
290
290
 
291
- Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
291
+ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
292
292
 
293
293
  </section>
294
294
 
@@ -301,8 +301,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
301
301
  [npm-image]: http://img.shields.io/npm/v/@stdlib/utils-map-reduce.svg
302
302
  [npm-url]: https://npmjs.org/package/@stdlib/utils-map-reduce
303
303
 
304
- [test-image]: https://github.com/stdlib-js/utils-map-reduce/actions/workflows/test.yml/badge.svg?branch=v0.2.0
305
- [test-url]: https://github.com/stdlib-js/utils-map-reduce/actions/workflows/test.yml?query=branch:v0.2.0
304
+ [test-image]: https://github.com/stdlib-js/utils-map-reduce/actions/workflows/test.yml/badge.svg?branch=v0.2.2
305
+ [test-url]: https://github.com/stdlib-js/utils-map-reduce/actions/workflows/test.yml?query=branch:v0.2.2
306
306
 
307
307
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/utils-map-reduce/main.svg
308
308
  [coverage-url]: https://codecov.io/github/stdlib-js/utils-map-reduce?branch=main
@@ -314,8 +314,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
314
314
 
315
315
  -->
316
316
 
317
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
318
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
317
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
318
+ [chat-url]: https://stdlib.zulipchat.com
319
319
 
320
320
  [stdlib]: https://github.com/stdlib-js/stdlib
321
321
 
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/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Performs a map-reduce operation against each element in an array and returns the accumulated result.\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 {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\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 cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\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 ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduce( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduce( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\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\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\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\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\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\tacc = initial;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Performs a map-reduce operation against each element in an array and returns the accumulated result.\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 {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduce( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduce( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = 0; i < xbuf.length; i++ ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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 format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduce( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\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 = mapReduce( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduce( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\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 = mapReduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce\n*\n* @example\n* var mapReduce = require( '@stdlib/utils-map-reduce' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduce( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduce = require( '@stdlib/utils-map-reduce' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduce( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Performs a map-reduce operation against each element in an array and returns the accumulated result.\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 {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\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 cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/complex-float64-base-add' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\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 ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduce( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduce( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\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\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\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\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\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\tacc = initial;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Performs a map-reduce operation against each element in an array and returns the accumulated result.\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 {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduce( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduce( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = 0; i < xbuf.length; i++ ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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 format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduce( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/number-float64-base-add' );\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 = mapReduce( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduce( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\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 = mapReduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce\n*\n* @example\n* var mapReduce = require( '@stdlib/utils-map-reduce' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduce( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/number-float64-base-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduce = require( '@stdlib/utils-map-reduce' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduce( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
5
  "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAWC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC1D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAI,EAAGA,EAAIP,EAAKO,IACrBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAWC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC1D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7BD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAWC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CAC5D,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA",
6
6
  "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduce", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduce", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduce", "arr", "initial", "mapper", "reducer", "thisArg", "main"]
7
7
  }
@@ -195,7 +195,7 @@ type ArrayReducer<U, V, T, W> = NullaryReducer<V, W> | UnaryReducer<V, W> | Bina
195
195
  * @example
196
196
  * var naryFunction = require( '@stdlib/utils-nary-function' );
197
197
  * var abs = require( '@stdlib/math-base-special-abs' );
198
- * var add = require( '@stdlib/math-base-ops-add' );
198
+ * var add = require( '@stdlib/number-float64-base-add' );
199
199
  * var array = require( '@stdlib/ndarray-array' );
200
200
  *
201
201
  * var opts = {
package/lib/index.js CHANGED
@@ -36,12 +36,12 @@
36
36
  *
37
37
  * var arr = [ 1, 2, 3, 4 ];
38
38
  *
39
- * var out = mapReduce( arr, 0, sum );
39
+ * var out = mapReduce( arr, 0, square, sum );
40
40
  * // returns 30
41
41
  *
42
42
  * @example
43
43
  * var naryFunction = require( '@stdlib/utils-nary-function' );
44
- * var add = require( '@stdlib/math-base-ops-add' );
44
+ * var add = require( '@stdlib/number-float64-base-add' );
45
45
  * var abs = require( '@stdlib/math-base-special-abs' );
46
46
  * var array = require( '@stdlib/ndarray-array' );
47
47
  * var mapReduce = require( '@stdlib/utils-map-reduce' );
package/lib/main.js CHANGED
@@ -76,7 +76,7 @@ var arrayFcn = require( './array.js' );
76
76
  *
77
77
  * @example
78
78
  * var naryFunction = require( '@stdlib/utils-nary-function' );
79
- * var add = require( '@stdlib/math-base-ops-add' );
79
+ * var add = require( '@stdlib/number-float64-base-add' );
80
80
  * var abs = require( '@stdlib/math-base-special-abs' );
81
81
  * var array = require( '@stdlib/ndarray-array' );
82
82
  *
package/lib/ndarray.js CHANGED
@@ -52,11 +52,11 @@ var MODE = 'throw';
52
52
  *
53
53
  * @example
54
54
  * var Complex64Array = require( '@stdlib/array-complex64' );
55
- * var Complex64 = require( '@stdlib/complex-float32' );
56
- * var realf = require( '@stdlib/complex-realf' );
57
- * var imagf = require( '@stdlib/complex-imagf' );
55
+ * var Complex64 = require( '@stdlib/complex-float32-ctor' );
56
+ * var realf = require( '@stdlib/complex-float32-real' );
57
+ * var imagf = require( '@stdlib/complex-float32-imag' );
58
58
  * var cceil = require( '@stdlib/math-base-special-cceil' );
59
- * var cadd = require( '@stdlib/math-base-ops-cadd' );
59
+ * var cadd = require( '@stdlib/complex-float64-base-add' );
60
60
  * var naryFunction = require( '@stdlib/utils-nary-function' );
61
61
  *
62
62
  * // Create a data buffer:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/utils-map-reduce",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Perform a single-pass map-reduce operation against each element in an array and return the accumulated result.",
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
- "test": "./test"
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,41 +30,16 @@
37
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
31
  },
39
32
  "dependencies": {
40
- "@stdlib/array-base-arraylike2object": "^0.2.0",
41
- "@stdlib/assert-is-array-like-object": "^0.2.0",
42
- "@stdlib/assert-is-function": "^0.2.0",
43
- "@stdlib/assert-is-ndarray-like": "^0.2.0",
44
- "@stdlib/ndarray-base-ndarraylike2object": "^0.2.0",
45
- "@stdlib/ndarray-base-vind2bind": "^0.2.0",
46
- "@stdlib/string-format": "^0.2.0",
47
- "@stdlib/types": "^0.3.1",
48
- "@stdlib/error-tools-fmtprodmsg": "^0.2.0"
49
- },
50
- "devDependencies": {
51
- "@stdlib/array-base-filled": "^0.2.0",
52
- "@stdlib/array-complex64": "^0.1.0",
53
- "@stdlib/array-filled-by": "^0.1.0",
54
- "@stdlib/array-float64": "^0.2.0",
55
- "@stdlib/complex-float32": "^0.2.0",
56
- "@stdlib/complex-imagf": "^0.2.0",
57
- "@stdlib/complex-realf": "^0.2.0",
58
- "@stdlib/math-base-assert-is-nan": "^0.2.0",
59
- "@stdlib/math-base-ops-add": "^0.2.0",
60
- "@stdlib/math-base-ops-cadd": "^0.2.0",
61
- "@stdlib/math-base-special-abs": "^0.2.0",
62
- "@stdlib/math-base-special-cceil": "^0.2.0",
63
- "@stdlib/math-base-special-pow": "^0.2.0",
64
- "@stdlib/ndarray-array": "^0.1.0",
65
- "@stdlib/ndarray-ctor": "^0.1.0",
66
- "@stdlib/random-base-discrete-uniform": "^0.1.0",
67
- "@stdlib/utils-nary-function": "^0.2.0",
68
- "@stdlib/utils-noop": "^0.2.0",
69
- "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
70
- "istanbul": "^0.4.1",
71
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
72
- "@stdlib/bench-harness": "^0.2.0",
73
- "@stdlib/bench": "^0.3.1"
33
+ "@stdlib/array-base-arraylike2object": "^0.2.2",
34
+ "@stdlib/assert-is-array-like-object": "^0.2.3",
35
+ "@stdlib/assert-is-function": "^0.2.3",
36
+ "@stdlib/assert-is-ndarray-like": "^0.2.2",
37
+ "@stdlib/ndarray-base-ndarraylike2object": "^0.2.3",
38
+ "@stdlib/ndarray-base-vind2bind": "^0.2.3",
39
+ "@stdlib/string-format": "^0.2.3",
40
+ "@stdlib/error-tools-fmtprodmsg": "^0.2.3"
74
41
  },
42
+ "devDependencies": {},
75
43
  "engines": {
76
44
  "node": ">=0.10.0",
77
45
  "npm": ">2.7.0"