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..f4575e9 100644 --- a/.github/workflows/productionize.yml +++ b/.github/workflows/productionize.yml @@ -94,8 +94,8 @@ jobs: node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" fi - # Configure git: - - name: 'Configure git' + # Configure Git: + - name: 'Configure Git' run: | git config --local user.email "noreply@stdlib.io" git config --local user.name "stdlib-bot" @@ -191,8 +191,8 @@ jobs: # Pin action to full length commit SHA uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - # Configure git: - - name: 'Configure git' + # Configure Git: + - name: 'Configure Git' run: | git config --local user.email "noreply@stdlib.io" git config --local user.name "stdlib-bot" @@ -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() @@ -367,8 +366,8 @@ jobs: # Pin action to full length commit SHA uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - # Configure git: - - name: 'Configure git' + # Configure Git: + - name: 'Configure Git' run: | git config --local user.email "noreply@stdlib.io" git config --local user.name "stdlib-bot" @@ -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() @@ -541,8 +539,8 @@ jobs: # Pin action to full length commit SHA uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - # Configure git: - - name: 'Configure git' + # Configure Git: + - name: 'Configure Git' run: | git config --local user.email "noreply@stdlib.io" git config --local user.name "stdlib-bot" @@ -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() @@ -738,8 +735,8 @@ jobs: echo "bump=true" >> $GITHUB_OUTPUT fi - # Configure git: - - name: 'Configure git' + # Configure Git: + - name: 'Configure Git' if: steps.check-if-bump.outputs.bump run: | git config --local user.email "noreply@stdlib.io" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3eec50e..2888b88 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -72,8 +72,8 @@ jobs: node-version: 20 timeout-minutes: 5 - # Configure git: - - name: 'Configure git' + # Configure Git: + - name: 'Configure Git' run: | git config --local user.email "noreply@stdlib.io" git config --local user.name "stdlib-bot" @@ -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}" @@ -202,7 +206,7 @@ jobs: # Publish package to npm: - name: 'Publish package to npm' # Pin action to full length commit SHA - uses: JS-DevTools/npm-publish@4b07b26a2f6e0a51846e1870223e545bae91c552 # v3.0.1 + uses: JS-DevTools/npm-publish@19c28f1ef146469e409470805ea4279d47c3d35c # v3.1.1 with: token: ${{ secrets.NPM_TOKEN }} access: public @@ -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 d6a4e0c..749ab0d 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 76036e5..3c0dfcc 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/.gitignore b/.gitignore index 49b206b..4fdc97c 100644 --- a/.gitignore +++ b/.gitignore @@ -101,6 +101,8 @@ docs/**/node_modules/ pids *.pid *.seed +yarn.lock +package-lock.json # Typescript # ############## diff --git a/.npmrc b/.npmrc index 5af9067..58dbd10 100644 --- a/.npmrc +++ b/.npmrc @@ -27,5 +27,5 @@ shrinkwrap = false # Disable automatically "saving" dependencies on install: save = false -# Generate provenance metadata: -provenance = true +# Do not generate provenance metadata: +provenance = false diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e4fd4d..1a2c034 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,4 +2,163 @@ > Package changelog. -See [GitHub Releases](https://github.com/stdlib-js/ndarray-base-unary-loop-interchange-order/releases) for the changelog. \ No newline at end of file +
+ +## Unreleased (2024-08-16) + +
+ +### Features + +- [`0d360b3`](https://github.com/stdlib-js/stdlib/commit/0d360b33eba8019d2d638f265986d861ed22642a) - return index array as part of the results object + +
+ + + +
+ +### Commits + +
+ +- [`0d360b3`](https://github.com/stdlib-js/stdlib/commit/0d360b33eba8019d2d638f265986d861ed22642a) - **feat:** return index array as part of the results object _(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) + +No changes reported for this release. + +
+ + + +
+ +## 0.2.0 (2024-02-15) + +
+ +### Commits + +
+ +- [`30e3541`](https://github.com/stdlib-js/stdlib/commit/30e35413446e1f46eb385bb811db2297bfc66bb0) - **refactor:** update require path _(by Athan Reines)_ +- [`8c8e3d1`](https://github.com/stdlib-js/stdlib/commit/8c8e3d15f6698c81c75fc94fa10a7e2b9fb8b5d9) - **docs:** update links _(by Athan Reines)_ +- [`453dd85`](https://github.com/stdlib-js/stdlib/commit/453dd85b5dd186d2b4d458256fe84906e1503fe2) - **build:** remove tslint directives _(by Philipp Burckhardt)_ + +
+ +
+ + + +
+ +### Contributors + +A total of 2 people contributed to this release. Thank you to the following contributors: + +- Athan Reines +- Philipp Burckhardt + +
+ + + +
+ + + +
+ +## 0.1.0 (2023-09-24) + +
+ +### Features + +- [`7ae5741`](https://github.com/stdlib-js/stdlib/commit/7ae574143c9716c82cea6cbf839a20b70a9cdfe0) - update minimum TypeScript version + +
+ + + +
+ +### BREAKING CHANGES + +- [`7ae5741`](https://github.com/stdlib-js/stdlib/commit/7ae574143c9716c82cea6cbf839a20b70a9cdfe0): update minimum TypeScript version to 4.1 + + - To migrate, users should upgrade their TypeScript version to at least version 4.1. + +
+ + + +
+ +### Commits + +
+ +- [`7ae5741`](https://github.com/stdlib-js/stdlib/commit/7ae574143c9716c82cea6cbf839a20b70a9cdfe0) - **feat:** update minimum TypeScript version _(by Philipp Burckhardt)_ +- [`80b8444`](https://github.com/stdlib-js/stdlib/commit/80b8444ae4991062d8961b2a020d24c2fe7a8a48) - **docs:** fix typo _(by Athan Reines)_ +- [`8df288a`](https://github.com/stdlib-js/stdlib/commit/8df288ad176e2b374f61112a37091b47462f0ec5) - **docs:** fix comment _(by Athan Reines)_ + +
+ +
+ + + +
+ +### Contributors + +A total of 2 people contributed to this release. Thank you to the following contributors: + +- Athan Reines +- Philipp Burckhardt + +
+ + + +
+ + + +
+ +## 0.0.1 (2023-02-02) + +No changes reported for this release. + +
+ + + diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 4500383..f05b39c 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 @@ -48,6 +51,7 @@ Muhammad Haris Naresh Jagadeesan NightKnight Nithin Katta <88046362+nithinkatta@users.noreply.github.com> +Nourhan Hasan <109472010+TheNourhan@users.noreply.github.com> Ognjen Jevremović Oneday12323 <107678750+Oneday12323@users.noreply.github.com> Philipp Burckhardt @@ -60,17 +64,22 @@ 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> Ryan Seal Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com> +SarthakPaandey <145528240+SarthakPaandey@users.noreply.github.com> 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 +88,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 6b6ad23..2d7d897 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ The function returns an object having the following properties: - **sh**: ordered dimensions. - **sx**: input array strides sorted in loop order. - **sy**: output array strides sorted in loop order. +- **idx**: dimension indices sorted in loop order. For all returned arrays, the first element corresponds to the innermost loop, and the last element corresponds to the outermost loop. diff --git a/dist/index.js b/dist/index.js index a4596be..e05422a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,7 +1,7 @@ -"use strict";var q=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=q(function(O,f){ -function j(e,r){var i,a,n,s,v,t,o,p,u,c;for(n=1,s=1,c=1;c=0&&(u=e[v],a=u<0?-u:u,!(a<=i));)e[v+1]=u,r[t+1]=r[t],v-=1,t-=1;e[v+1]=o,r[t+1]=p,n+=1,s+=1}}f.exports=j +"use strict";var q=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var f=q(function(O,x){ +function j(e,r){var i,a,n,s,v,t,o,p,u,c;for(n=1,s=1,c=1;c=0&&(u=e[v],a=u<0?-u:u,!(a<=i));)e[v+1]=u,r[t+1]=r[t],v-=1,t-=1;e[v+1]=o,r[t+1]=p,n+=1,s+=1}}x.exports=j });var g=q(function(T,d){ -var k=require('@stdlib/array-base-zero-to/dist'),b=require('@stdlib/array-base-copy-indexed/dist'),x=require('@stdlib/array-base-take-indexed/dist'),h=l();function m(e,r,i){var a;return a=k(e.length),r=b(r),h(r,a),e=x(e,a),i=x(i,a),{sh:e,sx:r,sy:i}}d.exports=m +var k=require('@stdlib/array-base-zero-to/dist'),b=require('@stdlib/array-base-copy-indexed/dist'),l=require('@stdlib/array-base-take-indexed/dist'),h=f();function m(e,r,i){var a;return a=k(e.length),r=b(r),h(r,a),e=l(e,a),i=l(i,a),{sh:e,sx:r,sy:i,idx:a}}d.exports=m });var w=g();module.exports=w; /** @license Apache-2.0 */ //# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map index 3ae950b..eacc1a7 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../lib/sort2ins.js", "../lib/main.js", "../lib/index.js"], - "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// MAIN //\n\n/**\n* Simultaneously sorts two arrays based on the sort order of the first array using insertion sort.\n*\n* ## Notes\n*\n* - The first array is sorted in increasing order according to absolute value.\n* - The algorithm has space complexity `O(1)` and worst case time complexity `O(N^2)`.\n* - The algorithm is efficient for small arrays (typically `N <= 20``) and is particularly efficient for sorting arrays which are already substantially sorted.\n* - The algorithm is **stable**, meaning that the algorithm does **not** change the order of array elements which are equal or equivalent.\n* - The input arrays are sorted in-place (i.e., the input arrays are mutated).\n*\n* @private\n* @param {Array} x - first array\n* @param {Array} y - second array\n* @returns {void}\n*\n* @example\n* var x = [ -4, -2, 3, 1 ];\n* var y = [ 0, 1, 2, 3 ];\n*\n* sort2ins( x, y );\n*\n* console.log( x );\n* // => [ 1, -2, 3, -4 ]\n*\n* console.log( y );\n* // => [ 3, 1, 2, 0 ]\n*/\nfunction sort2ins( x, y ) {\n\tvar avx;\n\tvar aux;\n\tvar ix;\n\tvar iy;\n\tvar jx;\n\tvar jy;\n\tvar vx;\n\tvar vy;\n\tvar ux;\n\tvar i;\n\n\tix = 1;\n\tiy = 1;\n\n\t// Sort in increasing order...\n\tfor ( i = 1; i < x.length; i++ ) {\n\t\tvx = x[ ix ];\n\t\tavx = ( vx < 0 ) ? -vx : vx;\n\n\t\tvy = y[ iy ];\n\n\t\tjx = ix - 1;\n\t\tjy = iy - 1;\n\n\t\t// Shift all larger values to the left of the current element to the right...\n\t\twhile ( jx >= 0 ) {\n\t\t\tux = x[ jx ];\n\t\t\taux = ( ux < 0 ) ? -ux : ux;\n\t\t\tif ( aux <= avx ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tx[ jx+1 ] = ux;\n\t\t\ty[ jy+1 ] = y[ jy ];\n\t\t\tjx -= 1;\n\t\t\tjy -= 1;\n\t\t}\n\t\tx[ jx+1 ] = vx;\n\t\ty[ jy+1 ] = vy;\n\t\tix += 1;\n\t\tiy += 1;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = sort2ins;\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 zeroTo = require( '@stdlib/array-base-zero-to' );\nvar copy = require( '@stdlib/array-base-copy-indexed' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar sort2ins = require( './sort2ins.js' );\n\n\n// MAIN //\n\n/**\n* Reorders ndarray dimensions and associated strides for loop interchange.\n*\n* ## Notes\n*\n* - The returned object has the following properties:\n*\n* - **sh**: dimensions sorted in loop order.\n* - **sx**: input ndarray strides sorted in loop order.\n* - **sy**: output ndarray strides sorted in loop order.\n*\n* @param {NonNegativeIntegerArray} sh - array dimensions\n* @param {IntegerArray} sx - input array stride lengths\n* @param {IntegerArray} sy - output array stride lengths\n* @returns {Object} loop interchange data\n*\n* @example\n* var sh = [ 2, 3, 4 ];\n*\n* var sx = [ 12, 4, 1 ]; // row-major\n* var sy = [ 1, -2, 6 ]; // column-major\n*\n* var o = loopOrder( sh, sx, sy );\n* // returns {...}\n*\n* var ssh = o.sh;\n* // returns [ 4, 3, 2 ]\n*\n* var ssx = o.sx;\n* // returns [ 1, 4, 12 ]\n*\n* var ssy = o.sy;\n* // returns [ 6, -2, 1 ]\n*/\nfunction loopOrder( sh, sx, sy ) {\n\tvar idx;\n\n\t// Initialize a loop interchange index array for generating a loop order permutation:\n\tidx = zeroTo( sh.length );\n\n\t// Sort the input array strides in increasing order (of magnitude):\n\tsx = copy( sx );\n\tsort2ins( sx, idx );\n\n\t// Permute the shape and output array strides based on the sorted input array strides:\n\tsh = take( sh, idx );\n\tsy = take( sy, idx );\n\n\treturn {\n\t\t'sh': sh,\n\t\t'sx': sx,\n\t\t'sy': sy\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = loopOrder;\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* Reorder ndarray dimensions and associated strides for loop interchange.\n*\n* @module @stdlib/ndarray-base-unary-loop-interchange-order\n*\n* @example\n* var unaryLoopOrder = require( '@stdlib/ndarray-base-unary-loop-interchange-order' );\n*\n* var sh = [ 2, 3, 4 ];\n*\n* var sx = [ 12, 4, 1 ]; // row-major\n* var sy = [ 1, -2, 6 ]; // column-major\n*\n* var o = unaryLoopOrder( sh, sx, sy );\n* // returns {...}\n*\n* var ssh = o.sh;\n* // returns [ 4, 3, 2 ]\n*\n* var ssx = o.sx;\n* // returns [ 1, 4, 12 ]\n*\n* var ssy = o.sy;\n* // returns [ 6, -2, 1 ]\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,cAkDA,SAASC,EAAUC,EAAGC,EAAI,CACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,IAJAP,EAAK,EACLC,EAAK,EAGCM,EAAI,EAAGA,EAAIX,EAAE,OAAQW,IAAM,CAUhC,IATAH,EAAKR,EAAGI,CAAG,EACXF,EAAQM,EAAK,EAAM,CAACA,EAAKA,EAEzBC,EAAKR,EAAGI,CAAG,EAEXC,EAAKF,EAAK,EACVG,EAAKF,EAAK,EAGFC,GAAM,IACbI,EAAKV,EAAGM,CAAG,EACXH,EAAQO,EAAK,EAAM,CAACA,EAAKA,EACpB,EAAAP,GAAOD,KAGZF,EAAGM,EAAG,CAAE,EAAII,EACZT,EAAGM,EAAG,CAAE,EAAIN,EAAGM,CAAG,EAClBD,GAAM,EACNC,GAAM,EAEPP,EAAGM,EAAG,CAAE,EAAIE,EACZP,EAAGM,EAAG,CAAE,EAAIE,EACZL,GAAM,EACNC,GAAM,CACP,CACD,CAKAP,EAAO,QAAUC,ICjGjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,4BAA6B,EAC/CC,EAAO,QAAS,iCAAkC,EAClDC,EAAO,QAAS,iCAAkC,EAClDC,EAAW,IAuCf,SAASC,EAAWC,EAAIC,EAAIC,EAAK,CAChC,IAAIC,EAGJ,OAAAA,EAAMR,EAAQK,EAAG,MAAO,EAGxBC,EAAKL,EAAMK,CAAG,EACdH,EAAUG,EAAIE,CAAI,EAGlBH,EAAKH,EAAMG,EAAIG,CAAI,EACnBD,EAAKL,EAAMK,EAAIC,CAAI,EAEZ,CACN,GAAMH,EACN,GAAMC,EACN,GAAMC,CACP,CACD,CAKAR,EAAO,QAAUK,ICxCjB,IAAIK,EAAO,IAKX,OAAO,QAAUA", + "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// MAIN //\n\n/**\n* Simultaneously sorts two arrays based on the sort order of the first array using insertion sort.\n*\n* ## Notes\n*\n* - The first array is sorted in increasing order according to absolute value.\n* - The algorithm has space complexity `O(1)` and worst case time complexity `O(N^2)`.\n* - The algorithm is efficient for small arrays (typically `N <= 20``) and is particularly efficient for sorting arrays which are already substantially sorted.\n* - The algorithm is **stable**, meaning that the algorithm does **not** change the order of array elements which are equal or equivalent.\n* - The input arrays are sorted in-place (i.e., the input arrays are mutated).\n*\n* @private\n* @param {Array} x - first array\n* @param {Array} y - second array\n* @returns {void}\n*\n* @example\n* var x = [ -4, -2, 3, 1 ];\n* var y = [ 0, 1, 2, 3 ];\n*\n* sort2ins( x, y );\n*\n* console.log( x );\n* // => [ 1, -2, 3, -4 ]\n*\n* console.log( y );\n* // => [ 3, 1, 2, 0 ]\n*/\nfunction sort2ins( x, y ) {\n\tvar avx;\n\tvar aux;\n\tvar ix;\n\tvar iy;\n\tvar jx;\n\tvar jy;\n\tvar vx;\n\tvar vy;\n\tvar ux;\n\tvar i;\n\n\tix = 1;\n\tiy = 1;\n\n\t// Sort in increasing order...\n\tfor ( i = 1; i < x.length; i++ ) {\n\t\tvx = x[ ix ];\n\t\tavx = ( vx < 0 ) ? -vx : vx;\n\n\t\tvy = y[ iy ];\n\n\t\tjx = ix - 1;\n\t\tjy = iy - 1;\n\n\t\t// Shift all larger values to the left of the current element to the right...\n\t\twhile ( jx >= 0 ) {\n\t\t\tux = x[ jx ];\n\t\t\taux = ( ux < 0 ) ? -ux : ux;\n\t\t\tif ( aux <= avx ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tx[ jx+1 ] = ux;\n\t\t\ty[ jy+1 ] = y[ jy ];\n\t\t\tjx -= 1;\n\t\t\tjy -= 1;\n\t\t}\n\t\tx[ jx+1 ] = vx;\n\t\ty[ jy+1 ] = vy;\n\t\tix += 1;\n\t\tiy += 1;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = sort2ins;\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 zeroTo = require( '@stdlib/array-base-zero-to' );\nvar copy = require( '@stdlib/array-base-copy-indexed' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar sort2ins = require( './sort2ins.js' );\n\n\n// MAIN //\n\n/**\n* Reorders ndarray dimensions and associated strides for loop interchange.\n*\n* ## Notes\n*\n* - The returned object has the following properties:\n*\n* - **sh**: dimensions sorted in loop order.\n* - **sx**: input ndarray strides sorted in loop order.\n* - **sy**: output ndarray strides sorted in loop order.\n* - **idx**: dimension indices sorted in loop order.\n*\n* @param {NonNegativeIntegerArray} sh - array dimensions\n* @param {IntegerArray} sx - input array stride lengths\n* @param {IntegerArray} sy - output array stride lengths\n* @returns {Object} loop interchange data\n*\n* @example\n* var sh = [ 2, 3, 4 ];\n*\n* var sx = [ 12, 4, 1 ]; // row-major\n* var sy = [ 1, -2, 6 ]; // column-major\n*\n* var o = loopOrder( sh, sx, sy );\n* // returns {...}\n*\n* var ssh = o.sh;\n* // returns [ 4, 3, 2 ]\n*\n* var ssx = o.sx;\n* // returns [ 1, 4, 12 ]\n*\n* var ssy = o.sy;\n* // returns [ 6, -2, 1 ]\n*\n* var idx = o.idx;\n* // returns [ 2, 1, 0 ]\n*/\nfunction loopOrder( sh, sx, sy ) {\n\tvar idx;\n\n\t// Initialize a loop interchange index array for generating a loop order permutation:\n\tidx = zeroTo( sh.length );\n\n\t// Sort the input array strides in increasing order (of magnitude):\n\tsx = copy( sx );\n\tsort2ins( sx, idx );\n\n\t// Permute the shape and output array strides based on the sorted input array strides:\n\tsh = take( sh, idx );\n\tsy = take( sy, idx );\n\n\treturn {\n\t\t'sh': sh,\n\t\t'sx': sx,\n\t\t'sy': sy,\n\t\t'idx': idx\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = loopOrder;\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* Reorder ndarray dimensions and associated strides for loop interchange.\n*\n* @module @stdlib/ndarray-base-unary-loop-interchange-order\n*\n* @example\n* var unaryLoopOrder = require( '@stdlib/ndarray-base-unary-loop-interchange-order' );\n*\n* var sh = [ 2, 3, 4 ];\n*\n* var sx = [ 12, 4, 1 ]; // row-major\n* var sy = [ 1, -2, 6 ]; // column-major\n*\n* var o = unaryLoopOrder( sh, sx, sy );\n* // returns {...}\n*\n* var ssh = o.sh;\n* // returns [ 4, 3, 2 ]\n*\n* var ssx = o.sx;\n* // returns [ 1, 4, 12 ]\n*\n* var ssy = o.sy;\n* // returns [ 6, -2, 1 ]\n*\n* var idx = o.idx;\n* // returns [ 2, 1, 0 ]\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,cAkDA,SAASC,EAAUC,EAAGC,EAAI,CACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,IAJAP,EAAK,EACLC,EAAK,EAGCM,EAAI,EAAGA,EAAIX,EAAE,OAAQW,IAAM,CAUhC,IATAH,EAAKR,EAAGI,CAAG,EACXF,EAAQM,EAAK,EAAM,CAACA,EAAKA,EAEzBC,EAAKR,EAAGI,CAAG,EAEXC,EAAKF,EAAK,EACVG,EAAKF,EAAK,EAGFC,GAAM,IACbI,EAAKV,EAAGM,CAAG,EACXH,EAAQO,EAAK,EAAM,CAACA,EAAKA,EACpB,EAAAP,GAAOD,KAGZF,EAAGM,EAAG,CAAE,EAAII,EACZT,EAAGM,EAAG,CAAE,EAAIN,EAAGM,CAAG,EAClBD,GAAM,EACNC,GAAM,EAEPP,EAAGM,EAAG,CAAE,EAAIE,EACZP,EAAGM,EAAG,CAAE,EAAIE,EACZL,GAAM,EACNC,GAAM,CACP,CACD,CAKAP,EAAO,QAAUC,ICjGjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,4BAA6B,EAC/CC,EAAO,QAAS,iCAAkC,EAClDC,EAAO,QAAS,iCAAkC,EAClDC,EAAW,IA2Cf,SAASC,EAAWC,EAAIC,EAAIC,EAAK,CAChC,IAAIC,EAGJ,OAAAA,EAAMR,EAAQK,EAAG,MAAO,EAGxBC,EAAKL,EAAMK,CAAG,EACdH,EAAUG,EAAIE,CAAI,EAGlBH,EAAKH,EAAMG,EAAIG,CAAI,EACnBD,EAAKL,EAAMK,EAAIC,CAAI,EAEZ,CACN,GAAMH,EACN,GAAMC,EACN,GAAMC,EACN,IAAOC,CACR,CACD,CAKAT,EAAO,QAAUK,IC1CjB,IAAIK,EAAO,IAKX,OAAO,QAAUA", "names": ["require_sort2ins", "__commonJSMin", "exports", "module", "sort2ins", "x", "y", "avx", "aux", "ix", "iy", "jx", "jy", "vx", "vy", "ux", "i", "require_main", "__commonJSMin", "exports", "module", "zeroTo", "copy", "take", "sort2ins", "loopOrder", "sh", "sx", "sy", "idx", "main"] } diff --git a/docs/repl.txt b/docs/repl.txt index 176ca53..28c5c74 100644 --- a/docs/repl.txt +++ b/docs/repl.txt @@ -7,6 +7,7 @@ - sh: ordered dimensions. - sx: input array strides sorted in loop order. - sy: output array strides sorted in loop order. + - idx: dimension indices sorted in loop order. For all returned arrays, the first element corresponds to the innermost loop, and the last element corresponds to the outermost loop. @@ -39,6 +40,9 @@ out.sy: Array Output array strides sorted in loop order. + out.idx: Array + Dimension indices sorted in loop order. + Examples -------- > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts index 9755d67..67116da 100644 --- a/docs/types/index.d.ts +++ b/docs/types/index.d.ts @@ -40,6 +40,11 @@ interface LoopOrderObject { * Output array strides sorted in loop order. */ sy: Array; + + /** + * Dimension indices sorted in loop order. + */ + idx: Array; } /** @@ -52,6 +57,7 @@ interface LoopOrderObject { * - **sh**: dimensions sorted in loop order. * - **sx**: input ndarray strides sorted in loop order. * - **sy**: output ndarray strides sorted in loop order. +* - **idx**: dimension indices sorted in loop order. * * - When iterating over the elements of a multi-dimensional array, accessing elements which are closer in memory can improve performance. To this end, loop interchange is a technique used in loop nest optimization to improve locality of reference and take advantage of CPU cache. * @@ -83,6 +89,9 @@ interface LoopOrderObject { * * var ssy = o.sy; * // returns [ 6, -2, 1 ] +* +* var idx = o.idx; +* // returns [ 2, 1, 0 ] */ declare function unaryLoopOrder( shape: ArrayLike, stridesX: ArrayLike, stridesY: ArrayLike ): LoopOrderObject; diff --git a/lib/index.js b/lib/index.js index 513b050..9905098 100644 --- a/lib/index.js +++ b/lib/index.js @@ -42,6 +42,9 @@ * * var ssy = o.sy; * // returns [ 6, -2, 1 ] +* +* var idx = o.idx; +* // returns [ 2, 1, 0 ] */ // MODULES // diff --git a/lib/main.js b/lib/main.js index 0ebea68..0e0547e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -38,6 +38,7 @@ var sort2ins = require( './sort2ins.js' ); * - **sh**: dimensions sorted in loop order. * - **sx**: input ndarray strides sorted in loop order. * - **sy**: output ndarray strides sorted in loop order. +* - **idx**: dimension indices sorted in loop order. * * @param {NonNegativeIntegerArray} sh - array dimensions * @param {IntegerArray} sx - input array stride lengths @@ -61,6 +62,9 @@ var sort2ins = require( './sort2ins.js' ); * * var ssy = o.sy; * // returns [ 6, -2, 1 ] +* +* var idx = o.idx; +* // returns [ 2, 1, 0 ] */ function loopOrder( sh, sx, sy ) { var idx; @@ -79,7 +83,8 @@ function loopOrder( sh, sx, sy ) { return { 'sh': sh, 'sx': sx, - 'sy': sy + 'sy': sy, + 'idx': idx }; } diff --git a/package.json b/package.json index 4332265..4e80b70 100644 --- a/package.json +++ b/package.json @@ -37,20 +37,20 @@ "url": "https://github.com/stdlib-js/stdlib/issues" }, "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.1", - "@stdlib/array-base-take-indexed": "^0.2.1", + "@stdlib/array-base-copy-indexed": "^0.2.2", + "@stdlib/array-base-take-indexed": "^0.2.2", "@stdlib/array-base-zero-to": "^0.2.1", "@stdlib/types": "^0.3.2" }, "devDependencies": { - "@stdlib/assert-is-array": "^0.2.1", + "@stdlib/assert-is-array": "^0.2.2", "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", + "@stdlib/ndarray-base-shape2strides": "^0.2.2", "@stdlib/random-base-randu": "^0.2.1", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" + "@stdlib/bench-harness": "^0.2.2" }, "engines": { "node": ">=0.10.0", diff --git a/test/test.js b/test/test.js index c592dad..6f1286e 100644 --- a/test/test.js +++ b/test/test.js @@ -57,6 +57,9 @@ tape( 'the function returns loop interchange data (row-major)', function test( t t.strictEqual( isArray( o.sy ), true, 'returns expected value' ); t.deepEqual( o.sy, [ 1, 2, -4 ], 'returns expected value' ); + t.strictEqual( isArray( o.idx ), true, 'returns expected value' ); + t.deepEqual( o.idx, [ 2, 1, 0 ], 'returns expected value' ); + t.end(); }); @@ -84,6 +87,9 @@ tape( 'the function returns loop interchange data (column-major)', function test t.strictEqual( isArray( o.sy ), true, 'returns expected value' ); t.deepEqual( o.sy, [ -1, 4, 8 ], 'returns expected value' ); + t.strictEqual( isArray( o.idx ), true, 'returns expected value' ); + t.deepEqual( o.idx, [ 0, 1, 2 ], 'returns expected value' ); + t.end(); }); @@ -111,6 +117,9 @@ tape( 'the function returns loop interchange data (mixed order)', function test( t.strictEqual( isArray( o.sy ), true, 'returns expected value' ); t.deepEqual( o.sy, [ -8, -4, 1 ], 'returns expected value' ); + t.strictEqual( isArray( o.idx ), true, 'returns expected value' ); + t.deepEqual( o.idx, [ 2, 1, 0 ], 'returns expected value' ); + t.end(); }); @@ -119,5 +128,6 @@ tape( 'if provided empty arrays, the function returns empty arrays', function te t.deepEqual( o.sh, [], 'returns expected value' ); t.deepEqual( o.sx, [], 'returns expected value' ); t.deepEqual( o.sy, [], 'returns expected value' ); + t.deepEqual( o.idx, [], 'returns expected value' ); t.end(); });