@stdlib/utils-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
@@ -147,9 +147,9 @@ var mean = out / ctx.count;
147
147
 
148
148
  ```javascript
149
149
  var Complex64Array = require( '@stdlib/array-complex64' );
150
- var Complex64 = require( '@stdlib/complex-float32' );
151
- var realf = require( '@stdlib/complex-realf' );
152
- var imagf = require( '@stdlib/complex-imagf' );
150
+ var Complex64 = require( '@stdlib/complex-float32-ctor' );
151
+ var realf = require( '@stdlib/complex-float32-real' );
152
+ var imagf = require( '@stdlib/complex-float32-imag' );
153
153
 
154
154
  function sum( acc, z ) {
155
155
  var re1 = realf( acc );
@@ -191,7 +191,7 @@ var mean = out / ctx.count;
191
191
  var filledarrayBy = require( '@stdlib/array-filled-by' );
192
192
  var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory;
193
193
  var naryFunction = require( '@stdlib/utils-nary-function' );
194
- var add = require( '@stdlib/math-base-ops-add' );
194
+ var add = require( '@stdlib/number-float64-base-add' );
195
195
  var array = require( '@stdlib/ndarray-array' );
196
196
  var reduce = require( '@stdlib/utils-reduce' );
197
197
 
@@ -273,7 +273,7 @@ See [LICENSE][stdlib-license].
273
273
 
274
274
  ## Copyright
275
275
 
276
- Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
276
+ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
277
277
 
278
278
  </section>
279
279
 
@@ -286,8 +286,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
286
286
  [npm-image]: http://img.shields.io/npm/v/@stdlib/utils-reduce.svg
287
287
  [npm-url]: https://npmjs.org/package/@stdlib/utils-reduce
288
288
 
289
- [test-image]: https://github.com/stdlib-js/utils-reduce/actions/workflows/test.yml/badge.svg?branch=v0.2.0
290
- [test-url]: https://github.com/stdlib-js/utils-reduce/actions/workflows/test.yml?query=branch:v0.2.0
289
+ [test-image]: https://github.com/stdlib-js/utils-reduce/actions/workflows/test.yml/badge.svg?branch=v0.2.2
290
+ [test-url]: https://github.com/stdlib-js/utils-reduce/actions/workflows/test.yml?query=branch:v0.2.2
291
291
 
292
292
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/utils-reduce/main.svg
293
293
  [coverage-url]: https://codecov.io/github/stdlib-js/utils-reduce?branch=main
@@ -299,8 +299,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
299
299
 
300
300
  -->
301
301
 
302
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
303
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
302
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
303
+ [chat-url]: https://stdlib.zulipchat.com
304
304
 
305
305
  [stdlib]: https://github.com/stdlib-js/stdlib
306
306
 
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) 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 against an accumulator and 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} fcn - function to apply\n* @param {*} thisArg - 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 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.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\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 = reduce( x, new Complex64( 0.0, 0.0 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 16.0\n*\n* var im = imagf( v );\n* // returns 20.0\n*/\nfunction reduce( x, initial, fcn, 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 fcn.call( thisArg, initial, get( xbuf, ox ), 0, ref );\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 = fcn.call( thisArg, acc, get( xbuf, ix ), i, ref );\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduce;\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 against an accumulator and 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} fcn - function to apply\n* @param {*} thisArg - function execution context\n* @returns {*} accumulated result\n*\n* @example\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:\n* var out = reduce( x, 0, sum );\n* // returns 10\n*/\nfunction reduce( x, initial, fcn, 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 = fcn.call( thisArg, acc, get( xbuf, i ), i, xbuf );\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Applies a function against an accumulator and each element in an array and returns the accumulated result.\n*\n* ## Notes\n*\n* - The applied function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: 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} reducer - reduction 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* @returns {*} accumulated result\n*\n* @example\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = reduce( arr, 0, sum );\n* // returns 10\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\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 = reduce( arr, 0, naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction reduce( arr, initial, reducer, thisArg ) {\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third 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, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, reducer, thisArg );\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 = reduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 against an accumulator and each element in an array and return the accumulated result.\n*\n* @module @stdlib/utils-reduce\n*\n* @example\n* var reduce = require( '@stdlib/utils-reduce' );\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = reduce( arr, 0, sum );\n* // returns 10\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var array = require( '@stdlib/ndarray-array' );\n* var reduce = require( '@stdlib/utils-reduce' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts );\n*\n* var out = reduce( arr, 0, 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) 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 against an accumulator and 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} fcn - function to apply\n* @param {*} thisArg - 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 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.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\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 = reduce( x, new Complex64( 0.0, 0.0 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 16.0\n*\n* var im = imagf( v );\n* // returns 20.0\n*/\nfunction reduce( x, initial, fcn, 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 fcn.call( thisArg, initial, get( xbuf, ox ), 0, ref );\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 = fcn.call( thisArg, acc, get( xbuf, ix ), i, ref );\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduce;\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 against an accumulator and 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} fcn - function to apply\n* @param {*} thisArg - function execution context\n* @returns {*} accumulated result\n*\n* @example\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:\n* var out = reduce( x, 0, sum );\n* // returns 10\n*/\nfunction reduce( x, initial, fcn, 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 = fcn.call( thisArg, acc, get( xbuf, i ), i, xbuf );\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Applies a function against an accumulator and each element in an array and returns the accumulated result.\n*\n* ## Notes\n*\n* - The applied function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: 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} reducer - reduction 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* @returns {*} accumulated result\n*\n* @example\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = reduce( arr, 0, sum );\n* // returns 10\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/number-float64-base-add' );\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 = reduce( arr, 0, naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction reduce( arr, initial, reducer, thisArg ) {\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third 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, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, reducer, thisArg );\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 = reduce;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 against an accumulator and each element in an array and return the accumulated result.\n*\n* @module @stdlib/utils-reduce\n*\n* @example\n* var reduce = require( '@stdlib/utils-reduce' );\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = reduce( arr, 0, sum );\n* // returns 10\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/number-float64-base-add' );\n* var array = require( '@stdlib/ndarray-array' );\n* var reduce = require( '@stdlib/utils-reduce' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts );\n*\n* var out = reduce( arr, 0, 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,QAwEX,SAASC,EAAQC,EAAGC,EAASC,EAAKC,EAAU,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMP,EAAE,OAGRU,EAAMV,EAAE,MAGRI,EAAOJ,EAAE,KAGTW,EAAKX,EAAE,QAGPY,EAAKZ,EAAE,OAGPK,EAAOL,EAAE,MAGTQ,EAAMR,EAAE,UAAW,CAAE,EAGrBS,EAAMT,EAAE,IAGHU,EAAI,SAAW,EACnB,OAAOR,EAAI,KAAMC,EAASF,EAASO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAI5D,IADAH,EAAML,EACAa,EAAI,EAAGA,EAAIP,EAAKO,IACrBD,EAAKhB,EAAWa,EAAKC,EAAIC,EAAIP,EAAMS,EAAGhB,CAAK,EAC3CQ,EAAMJ,EAAI,KAAMC,EAASG,EAAKE,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAEvD,OAAOH,CACR,CAKAV,EAAO,QAAUG,ICxJjB,IAAAgB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsDA,SAASC,EAAQC,EAAGC,EAASC,EAAKC,EAAU,CAC3C,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOJ,EAAE,KAGTK,EAAML,EAAE,UAAW,CAAE,EAGrBM,EAAML,EACAM,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7BD,EAAMJ,EAAI,KAAMC,EAASG,EAAKD,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAEvD,OAAOE,CACR,CAKAR,EAAO,QAAUC,IC7EjB,IAAAS,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,IAgDf,SAASC,EAAQC,EAAKC,EAASC,EAASC,EAAU,CACjD,GAAK,CAACV,EAAYS,CAAQ,EACzB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAQ,CAAE,EAE7G,GAAKV,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAASC,CAAQ,EAEzE,GAAKZ,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAASC,CAAQ,EAErE,MAAM,IAAI,UAAWP,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,ICvCjB,IAAIK,EAAO,IAKX,OAAO,QAAUA",
6
6
  "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "reduce", "x", "initial", "fcn", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "reduce", "x", "initial", "fcn", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "reduce", "arr", "initial", "reducer", "thisArg", "main"]
7
7
  }
@@ -123,7 +123,7 @@ type ArrayReducer<T, U, V> = Nullary<U, V> | Unary<U, V> | Binary<T, U, V> | Ter
123
123
  *
124
124
  * @example
125
125
  * var naryFunction = require( '@stdlib/utils-nary-function' );
126
- * var add = require( '@stdlib/math-base-ops-add' );
126
+ * var add = require( '@stdlib/number-float64-base-add' );
127
127
  * var array = require( '@stdlib/ndarray-array' );
128
128
  *
129
129
  * var opts = {
package/lib/index.js CHANGED
@@ -37,7 +37,7 @@
37
37
  *
38
38
  * @example
39
39
  * var naryFunction = require( '@stdlib/utils-nary-function' );
40
- * var add = require( '@stdlib/math-base-ops-add' );
40
+ * var add = require( '@stdlib/number-float64-base-add' );
41
41
  * var array = require( '@stdlib/ndarray-array' );
42
42
  * var reduce = require( '@stdlib/utils-reduce' );
43
43
  *
package/lib/main.js CHANGED
@@ -64,7 +64,7 @@ var arrayFcn = require( './array.js' );
64
64
  *
65
65
  * @example
66
66
  * var naryFunction = require( '@stdlib/utils-nary-function' );
67
- * var add = require( '@stdlib/math-base-ops-add' );
67
+ * var add = require( '@stdlib/number-float64-base-add' );
68
68
  * var array = require( '@stdlib/ndarray-array' );
69
69
  *
70
70
  * var opts = {
package/lib/ndarray.js CHANGED
@@ -51,10 +51,10 @@ var MODE = 'throw';
51
51
  *
52
52
  * @example
53
53
  * var Complex64Array = require( '@stdlib/array-complex64' );
54
- * var Complex64 = require( '@stdlib/complex-float32' );
55
- * var realf = require( '@stdlib/complex-realf' );
56
- * var imagf = require( '@stdlib/complex-imagf' );
57
- * var cadd = require( '@stdlib/math-base-ops-cadd' );
54
+ * var Complex64 = require( '@stdlib/complex-float32-ctor' );
55
+ * var realf = require( '@stdlib/complex-float32-real' );
56
+ * var imagf = require( '@stdlib/complex-float32-imag' );
57
+ * var cadd = require( '@stdlib/complex-float64-base-add' );
58
58
  * var naryFunction = require( '@stdlib/utils-nary-function' );
59
59
  *
60
60
  * // Create a data buffer:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/utils-reduce",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Apply a function against an accumulator and 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,39 +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-pow": "^0.2.0",
62
- "@stdlib/ndarray-array": "^0.1.0",
63
- "@stdlib/ndarray-ctor": "^0.1.0",
64
- "@stdlib/random-base-discrete-uniform": "^0.1.0",
65
- "@stdlib/utils-nary-function": "^0.2.0",
66
- "@stdlib/utils-noop": "^0.2.0",
67
- "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
68
- "istanbul": "^0.4.1",
69
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
70
- "@stdlib/bench-harness": "^0.2.0",
71
- "@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"
72
41
  },
42
+ "devDependencies": {},
73
43
  "engines": {
74
44
  "node": ">=0.10.0",
75
45
  "npm": ">2.7.0"