From fb9ab4f3dafb2327e533271f9959ce0e1e244944 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 18 Jul 2024 01:36:49 +0000 Subject: [PATCH] Auto-generated commit --- .gitattributes | 29 ++++++-- .github/workflows/productionize.yml | 3 - .github/workflows/publish.yml | 5 +- .github/workflows/test.yml | 1 - .github/workflows/test_bundles.yml | 3 - .github/workflows/test_coverage.yml | 1 - .github/workflows/test_install.yml | 1 - CHANGELOG.md | 109 +++++++++++++++++++++++++++- CONTRIBUTORS | 11 ++- README.md | 6 +- dist/index.js.map | 2 +- lib/ndarray.js | 8 +- package.json | 8 +- test/test.js | 8 +- 14 files changed, 161 insertions(+), 34 deletions(-) diff --git a/.gitattributes b/.gitattributes index 10a16e6..1c88e69 100644 --- a/.gitattributes +++ b/.gitattributes @@ -40,10 +40,27 @@ *.mov binary # Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false +/lib/node_modules/** -linguist-vendored -linguist-generated -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false +# Configure directories which should *not* be included in GitHub language statistics: +/deps/** linguist-vendored +/dist/** linguist-generated +/workshops/** linguist-vendored + +benchmark/** linguist-vendored +docs/* linguist-documentation +etc/** linguist-vendored +examples/** linguist-documentation +scripts/** linguist-vendored +test/** linguist-vendored +tools/** linguist-vendored + +# Configure files which should *not* be included in GitHub language statistics: +Makefile linguist-vendored +*.mk linguist-vendored +*.jl linguist-vendored +*.py linguist-vendored +*.R linguist-vendored + +# Configure files which should be included in GitHub language statistics: +docs/types/*.d.ts -linguist-documentation diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml index ec90164..f92a6c5 100644 --- a/.github/workflows/productionize.yml +++ b/.github/workflows/productionize.yml @@ -344,7 +344,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() @@ -518,7 +517,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() @@ -698,7 +696,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3eec50e..b1d4bb8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -94,6 +94,10 @@ jobs: # Replace branch in README.md link definitions for badges with the new version: find . -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/branch([=:])[^ ]+/branch\1v${NEW_VERSION}/g" + # Rewrite CHANGELOG.md to replace "Unreleased" with the new version: + sed -Ei "s/Unreleased/${NEW_VERSION}/g" CHANGELOG.md + sed -Ei "s/unreleased/v${NEW_VERSION}/g" CHANGELOG.md + # Create a new commit and tag: git add package.json README.md git commit -m "Release v${NEW_VERSION}" @@ -218,7 +222,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 769071c..0d8456c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -95,6 +95,5 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/.github/workflows/test_bundles.yml b/.github/workflows/test_bundles.yml index 6d77abd..5b5879a 100644 --- a/.github/workflows/test_bundles.yml +++ b/.github/workflows/test_bundles.yml @@ -94,7 +94,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() @@ -139,7 +138,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() @@ -184,6 +182,5 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml index f4eda1e..2bcf0cd 100644 --- a/.github/workflows/test_coverage.yml +++ b/.github/workflows/test_coverage.yml @@ -119,7 +119,6 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/.github/workflows/test_install.yml b/.github/workflows/test_install.yml index e1c1d16..66fa381 100644 --- a/.github/workflows/test_install.yml +++ b/.github/workflows/test_install.yml @@ -81,6 +81,5 @@ jobs: uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 with: status: ${{ job.status }} - steps: ${{ toJson(steps) }} channel: '#npm-ci' if: failure() diff --git a/CHANGELOG.md b/CHANGELOG.md index 64100d8..f78fdf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,4 +2,111 @@ > Package changelog. -See [GitHub Releases](https://github.com/stdlib-js/utils-reduce/releases) for the changelog. \ No newline at end of file +
+ +## Unreleased (2024-07-18) + +
+ +### Commits + +
+ +- [`0406147`](https://github.com/stdlib-js/stdlib/commit/04061476d1036e1b8b786736b1ba1653eddff1ef) - **refactor:** update paths _(by Athan Reines)_ +- [`8d4c46b`](https://github.com/stdlib-js/stdlib/commit/8d4c46b10ca912401e0ff0caa37a17cd3c443c2f) - **refactor:** update paths _(by Athan Reines)_ +- [`18b3c79`](https://github.com/stdlib-js/stdlib/commit/18b3c79c5035c7082618b7379cd6576e64393a96) - **refactor:** update paths _(by Athan Reines)_ +- [`75d4f83`](https://github.com/stdlib-js/stdlib/commit/75d4f83cb85610d23a04dc21a03f8075f6d3665f) - **refactor:** update require and include paths _(by Athan Reines)_ + +
+ +
+ + + +
+ +### Contributors + +A total of 1 person contributed to this release. Thank you to this contributor: + +- Athan Reines + +
+ + + +
+ + + +
+ +## 0.2.1 (2024-02-25) + +
+ +### Features + +- [`ace728f`](https://github.com/stdlib-js/stdlib/commit/ace728f330033182c28199dc9e13d75eda18cfe0) - update minimum TypeScript version + +
+ + + +
+ +### Bug Fixes + +- [`90b28d6`](https://github.com/stdlib-js/stdlib/commit/90b28d6e257dc731e846a16029768d3af57d1082) - update import path for `Collection` type definition and improve type specificity + +
+ + + +
+ +### BREAKING CHANGES + +- [`ace728f`](https://github.com/stdlib-js/stdlib/commit/ace728f330033182c28199dc9e13d75eda18cfe0): update minimum TypeScript version +- [`ace728f`](https://github.com/stdlib-js/stdlib/commit/ace728f330033182c28199dc9e13d75eda18cfe0): update minimum TypeScript version to 4.1 + + - To migrate, users should upgrade their TypeScript version to at least version 4.1. + +
+ + + +
+ +### Commits + +
+ +- [`dea49e0`](https://github.com/stdlib-js/stdlib/commit/dea49e03ab5571233e3da26835a6a6d3256d5737) - **docs:** use single quotes in require calls instead of backticks _(by Philipp Burckhardt)_ +- [`cacca61`](https://github.com/stdlib-js/stdlib/commit/cacca61bc884c5c1805716236733cf378d0ce955) - **docs:** update links _(by Athan Reines)_ +- [`90b28d6`](https://github.com/stdlib-js/stdlib/commit/90b28d6e257dc731e846a16029768d3af57d1082) - **fix:** update import path for `Collection` type definition and improve type specificity _(by Athan Reines)_ +- [`ace728f`](https://github.com/stdlib-js/stdlib/commit/ace728f330033182c28199dc9e13d75eda18cfe0) - **feat:** update minimum TypeScript version _(by Philipp Burckhardt)_ + +
+ +
+ + + +
+ +### Contributors + +A total of 2 people contributed to this release. Thank you to the following contributors: + +- Athan Reines +- Philipp Burckhardt + +
+ + + +
+ + + diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 4500383..7ec15a7 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -5,6 +5,7 @@ Adarsh Palaskar Aditya Sapra AgPriyanshu18 <113460573+AgPriyanshu18@users.noreply.github.com> +Aleksandr <112382387+alextes90@users.noreply.github.com> Ali Salesi Aman Bhansali Amit Jimiwal @@ -18,6 +19,7 @@ Chinmay Joshi <86140365+JawHawk@users.noreply.github.com> Christopher Dambamuromo Dan Rose Daniel Killenberger +Daniel Yu <40680511+Daniel777y@users.noreply.github.com> Dominik Moritz Dorrin Sotoudeh EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> @@ -25,6 +27,7 @@ Frank Kovacs Golden Kumar <103646877+AuenKr@users.noreply.github.com> Gunj Joshi Harshita Kalani +Hridyanshu <124202756+HRIDYANSHU054@users.noreply.github.com> Jaimin Godhani <112328542+Jai0401@users.noreply.github.com> James Gelok Jaysukh Makvana @@ -60,6 +63,7 @@ Pushpendra Chandravanshi Raunak Kumar Gupta Rejoan Sardar <119718513+Rejoan-Sardar@users.noreply.github.com> Ricky Reusser +Ridam Garg <67867319+RidamGarg@users.noreply.github.com> Robert Gislason Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com> Rutam <138517416+performant23@users.noreply.github.com> @@ -69,8 +73,11 @@ Seyyed Parsa Neshaei Shashank Shekhar Singh Shivam <11shivam00@gmail.com> Shraddheya Shendre +Shubh Mehta <93862397+Shubh942@users.noreply.github.com> Shubham Mishra -Snehil Shah <130062020+Snehil-Shah@users.noreply.github.com> +Sivam Das <100067002+Sivam2313@users.noreply.github.com> +Snehil Shah +Soumajit Chatterjee <121816890+soumajit23@users.noreply.github.com> Spandan Barve Stephannie Jiménez Gacha Suraj kumar <125961509+kumarsuraj212003@users.noreply.github.com> @@ -79,8 +86,10 @@ Tudor Pagu <104032457+tudor-pagu@users.noreply.github.com> Utkarsh Utkarsh Raj Varad Gupta +Xiaochuan Ye Yernar Yergaziyev naveen nishant-s7 <97207366+nishant-s7@users.noreply.github.com> orimiles5 <97595296+orimiles5@users.noreply.github.com> +rainn <88160429+AmCodesLame@users.noreply.github.com> rei2hu diff --git a/README.md b/README.md index 95147fd..40f44f1 100644 --- a/README.md +++ b/README.md @@ -157,9 +157,9 @@ var mean = out / ctx.count; ```javascript var Complex64Array = require( '@stdlib/array-complex64' ); - var Complex64 = require( '@stdlib/complex-float32' ); - var realf = require( '@stdlib/complex-realf' ); - var imagf = require( '@stdlib/complex-imagf' ); + var Complex64 = require( '@stdlib/complex-float32-ctor' ); + var realf = require( '@stdlib/complex-float32-real' ); + var imagf = require( '@stdlib/complex-float32-imag' ); function sum( acc, z ) { var re1 = realf( acc ); diff --git a/dist/index.js.map b/dist/index.js.map index 22d4e76..55fe407 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "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} 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} 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"], + "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} 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} 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"], "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", "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"] } diff --git a/lib/ndarray.js b/lib/ndarray.js index 971f503..af564d5 100644 --- a/lib/ndarray.js +++ b/lib/ndarray.js @@ -51,10 +51,10 @@ var MODE = 'throw'; * * @example * var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); +* var Complex64 = require( '@stdlib/complex-float32-ctor' ); +* var realf = require( '@stdlib/complex-float32-real' ); +* var imagf = require( '@stdlib/complex-float32-imag' ); +* var cadd = require( '@stdlib/complex-float64-base-add' ); * var naryFunction = require( '@stdlib/utils-nary-function' ); * * // Create a data buffer: diff --git a/package.json b/package.json index d70d249..4866e8b 100644 --- a/package.json +++ b/package.json @@ -52,12 +52,12 @@ "@stdlib/array-complex64": "^0.2.1", "@stdlib/array-filled-by": "^0.2.1", "@stdlib/array-float64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", + "@stdlib/complex-float32-ctor": "^0.0.1", + "@stdlib/complex-float32-imag": "^0.1.0", + "@stdlib/complex-float32-real": "^0.1.0", + "@stdlib/complex-float64-base-add": "github:stdlib-js/complex-float64-base-add#main", "@stdlib/math-base-assert-is-nan": "^0.2.1", "@stdlib/math-base-ops-add": "^0.2.1", - "@stdlib/math-base-ops-cadd": "^0.2.1", "@stdlib/math-base-special-pow": "^0.2.1", "@stdlib/ndarray-array": "^0.2.1", "@stdlib/ndarray-ctor": "^0.2.1", diff --git a/test/test.js b/test/test.js index a3ff5d9..f1f32c6 100644 --- a/test/test.js +++ b/test/test.js @@ -24,14 +24,14 @@ var tape = require( 'tape' ); var noop = require( '@stdlib/utils-noop' ); var naryFunction = require( '@stdlib/utils-nary-function' ); var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); +var cadd = require( '@stdlib/complex-float64-base-add' ); var Float64Array = require( '@stdlib/array-float64' ); var Complex64Array = require( '@stdlib/array-complex64' ); var array = require( '@stdlib/ndarray-array' ); var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); +var Complex64 = require( '@stdlib/complex-float32-ctor' ); +var realf = require( '@stdlib/complex-float32-real' ); +var imagf = require( '@stdlib/complex-float32-imag' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); var reduce = require( './../lib' );