From 3b10624930da3a1e24b5cabd1281914c04ffe202 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 10:01:58 +0000 Subject: [PATCH 01/73] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..a72c7f0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index 22b1d39..2b03286 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 5eee3a43f70efb8b63f6af3f70ab0cefb48b8fed Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 10:26:24 +0000 Subject: [PATCH 02/73] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 41 files changed, 6207 insertions(+), 4560 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index dc21272..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -221,7 +214,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -283,9 +276,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8c2b762..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4761e74..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index fdfdfef..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('null4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('null2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('null2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('nullF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('nullF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index c665522..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x.shape );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 57773ea..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe6b67f..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1b30ed..66968a0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..35a7d79 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6038646 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 693b8ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x.shape ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a72c7f0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 2b03286..f40d2c2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1120022 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From aa9e025a5280c5e8788f947db6f5e505ebd980c8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 11:04:27 +0000 Subject: [PATCH 03/73] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..a72c7f0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index 22b1d39..2b03286 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 8e4f1d0611612ebdaa1839cbbce35d096f13fc82 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 11:07:49 +0000 Subject: [PATCH 04/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6273 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 66968a0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 35a7d79..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6038646..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1120022..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1d028d588a75ae8dceec2e6547448c1d8f8cdf93 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 11:09:04 +0000 Subject: [PATCH 05/73] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 41 files changed, 6207 insertions(+), 4560 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index dc21272..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -221,7 +214,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -283,9 +276,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8c2b762..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4761e74..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index fdfdfef..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('null4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('null2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('null2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('nullF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('nullF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index c665522..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x.shape );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 57773ea..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1b30ed..66968a0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..35a7d79 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6038646 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 693b8ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x.shape ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a72c7f0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 2b03286..f40d2c2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..861342c --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 2d1e94c4527e8e1b0e3cb3fb84f8aac1812b5570 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 13:44:45 +0000 Subject: [PATCH 06/73] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..a72c7f0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index 7ac394a..62f3052 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 403e26f07509d866f51059a61323cfa4af056105 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 13:56:32 +0000 Subject: [PATCH 07/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6273 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 66968a0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 35a7d79..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6038646..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 861342c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e41223d1f6154c1279a7bd752ba2b7126d4bc13b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 13:57:37 +0000 Subject: [PATCH 08/73] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 41 files changed, 6207 insertions(+), 4560 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index dc21272..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -221,7 +214,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -283,9 +276,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8c2b762..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4761e74..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index fdfdfef..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('null4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('null2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('null2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('nullF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('nullF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index c665522..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x.shape );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 57773ea..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1b30ed..66968a0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..35a7d79 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6038646 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 693b8ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x.shape ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a72c7f0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 62f3052..b032d77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..356428b --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 2e0ea1f6536e265893f45315ea06f3d0f6b725b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 14:00:05 +0000 Subject: [PATCH 09/73] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6a32fc1..816cf2f 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.1.0-esm/index.mjs'; ``` #### nditerRowEntries( x\[, options] ) @@ -159,7 +159,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.1.0-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From ae75c515b3e80a4497058ca0edaa2fe3918ce715 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 14:00:06 +0000 Subject: [PATCH 10/73] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 816cf2f..8a34efb 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-row-entries/tags). For example, + ```javascript import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.1.0-esm/index.mjs'; ``` @@ -159,7 +164,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.1.0-esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 300ee4afdb328e2872faafd30134c96ccab7a397 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 20:27:56 +0000 Subject: [PATCH 11/73] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..a72c7f0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index 7ac394a..62f3052 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 8588febfddf1d7fd5d98088f1284df2937eb2114 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 20:31:19 +0000 Subject: [PATCH 12/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6273 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 66968a0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 35a7d79..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6038646..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 356428b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7267f86aa40f505067bb5f1d70512906bc307e82 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 20:32:17 +0000 Subject: [PATCH 13/73] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 41 files changed, 6207 insertions(+), 4560 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index dc21272..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -221,7 +214,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -283,9 +276,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8c2b762..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4761e74..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index fdfdfef..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('null4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('null2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('null2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('nullF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('nullF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index c665522..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x.shape );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1b30ed..66968a0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..35a7d79 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6038646 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 693b8ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x.shape ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a72c7f0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 62f3052..b032d77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3cfc10e --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 9ff608e9bb9a647c181bf2de11c46c1edee9b75a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 22:22:33 +0000 Subject: [PATCH 14/73] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..a72c7f0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index 7ac394a..62f3052 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From aecb65998305a418a9efda14fce58a5632bd0368 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 22:39:47 +0000 Subject: [PATCH 15/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6273 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 66968a0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 35a7d79..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6038646..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3cfc10e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4117cce21f33cb0e5d88aa80c9147c92a203a55e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 22:40:57 +0000 Subject: [PATCH 16/73] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 41 files changed, 6207 insertions(+), 4560 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index dc21272..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -221,7 +214,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -283,9 +276,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8c2b762..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4761e74..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index fdfdfef..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('null4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('null2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('null2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('nullF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('nullF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1b30ed..66968a0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..35a7d79 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6038646 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a72c7f0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 62f3052..b032d77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..74a3bcf --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 90fedbadd2f8bab0c5a2f7566a9b0113e1cbd7fc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 12:52:10 +0000 Subject: [PATCH 17/73] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..a72c7f0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index eb00bac..2592dec 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From dc1a4a018544609417aaed4f6e596a7516a994a6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 16:42:45 +0000 Subject: [PATCH 18/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6273 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 66968a0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 35a7d79..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6038646..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 74a3bcf..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0163eea929100e5be414f8b018c4eb20f8d4a33d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 16:43:33 +0000 Subject: [PATCH 19/73] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 57 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 41 files changed, 6210 insertions(+), 4563 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index dc21272..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -230,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -292,17 +285,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8c2b762..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4761e74..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index fdfdfef..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('null4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('null2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('null2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('nullF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('nullF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1b30ed..66968a0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..35a7d79 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6038646 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a72c7f0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 2592dec..b032d77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5ba7c40 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 4895b5801ff9f2ce57198e92616312afb6e82fc2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 13:26:38 +0000 Subject: [PATCH 20/73] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..a72c7f0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'writable': false @@ -102,11 +102,11 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { diff --git a/package.json b/package.json index 49a1efe..b4fc847 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 0fb2cd5ca30b056d890f1d1a349f3bfc9f391d36 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:25:26 +0000 Subject: [PATCH 21/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6273 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 66968a0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 35a7d79..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6038646..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5ba7c40..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1c2fbcd1f4675a0b7cbb91270fea5eccd9ba964f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:26:33 +0000 Subject: [PATCH 22/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 57 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 42 files changed, 6210 insertions(+), 4559 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 2570759..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T05:39:56.910Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index dc21272..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -230,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -292,17 +285,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8c2b762..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4761e74..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3975369..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('1lR4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('1lR2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('1lR2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('1lRF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('1lRF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1b30ed..66968a0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..35a7d79 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6038646 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index a72c7f0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index b4fc847..b032d77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8977cc5 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 7db8c8933814a657ef91abd424949af8ae6560dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:00:20 +0000 Subject: [PATCH 23/73] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 034388d..757a4d2 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 56bd110d7a8118237e449b92b42d384d6ad6ea9a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:39:17 +0000 Subject: [PATCH 24/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6273 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 66968a0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 35a7d79..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function v(b){var f,c,y,u,g,w,x,E,T,F,k;if(!t(b))throw new TypeError(h("null4f,Pc",b));if(u={writable:!1},arguments.length>1){if(!r(f=arguments[1]))throw new TypeError(h("null2V,FD",f));if(i(f,"readonly")){if(!s(f.readonly))throw new TypeError(h("null2o,GE","readonly",f.readonly));if(u.writable=!f.readonly,u.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((y=(c=l(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(c))&&(w=!0),F/=c[y-1],T=c[E=y-2],k=-1,(x=o(y))[y-1]=null,e(g={},"next",z),e(g,"return",C),d&&e(g,d,D),g;function z(){var e,r,s;return k+=1,w||k>=F?{done:!0}:(e=x.slice(),r=p(x),s=(x[E]+1)%T,x[E]=s,0===s&&(x=j(c,"row-major",x,E-1,x)),{value:[e,a(b,r,!0,u.writable)],done:!1})}function C(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function D(){return v(b,u)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6038646..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o,GE', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,YAAad,IAK3C,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAab,IAE3C,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,YAAa,WAAYb,EAAQoB,WAG/D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8977cc5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9ad5b6064eb64a1723cff52904dd04b70359107c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:39:37 +0000 Subject: [PATCH 25/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 57 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 43 files changed, 6210 insertions(+), 4565 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6fdbf77..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:09:16.286Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 3a158e5..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -230,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -292,17 +285,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4761e74..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3975369..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('1lR4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('1lR2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('1lR2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('1lRF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('1lRF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1b30ed..66968a0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..db23f43 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,c,y,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(c={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(c.writable=!u.readonly,c.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-1],T=f[E=g-2],O=-1,(x=o(g))[g-1]=null,e(y={},"next",V),e(y,"return",k),d&&e(y,d,z),y;function V(){var e,r,t;return O+=1,w||O>=F?{done:!0}:(e=x.slice(),r=p(x),t=(x[E]+1)%T,x[E]=t,0===t&&(x=j(f,"row-major",x,E-1,x)),{value:[e,l(b,r,!0,c.writable)],done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,c)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82476f2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;42CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d3f2c26..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 757a4d2..b032d77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "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.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f234be3 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 577ca301cf3eaa702595092660ed688572cc3a22 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:32:36 +0000 Subject: [PATCH 26/73] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 034388d..757a4d2 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 3504908a87dbd04fd0e906b88cad9f84fb9040dc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:54:30 +0000 Subject: [PATCH 27/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6273 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 66968a0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index db23f43..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,c,y,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(c={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(c.writable=!u.readonly,c.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-1],T=f[E=g-2],O=-1,(x=o(g))[g-1]=null,e(y={},"next",V),e(y,"return",k),d&&e(y,d,z),y;function V(){var e,r,t;return O+=1,w||O>=F?{done:!0}:(e=x.slice(),r=p(x),t=(x[E]+1)%T,x[E]=t,0===t&&(x=j(f,"row-major",x,E-1,x)),{value:[e,l(b,r,!0,c.writable)],done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,c)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 82476f2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;42CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f234be3..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 38742e4014c9ccc226d950cb1bd42d9be5dcdefd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:54:57 +0000 Subject: [PATCH 28/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 43 files changed, 6210 insertions(+), 4570 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 576b049..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T05:58:58.435Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 3a158e5..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3975369..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('1lR4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('1lR2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('1lR2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('1lRF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('1lRF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 89ac3c8..f183ca6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..db23f43 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,c,y,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(c={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(c.writable=!u.readonly,c.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-1],T=f[E=g-2],O=-1,(x=o(g))[g-1]=null,e(y={},"next",V),e(y,"return",k),d&&e(y,d,z),y;function V(){var e,r,t;return O+=1,w||O>=F?{done:!0}:(e=x.slice(),r=p(x),t=(x[E]+1)%T,x[E]=t,0===t&&(x=j(f,"row-major",x,E-1,x)),{value:[e,l(b,r,!0,c.writable)],done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,c)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82476f2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;42CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d3f2c26..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 757a4d2..b032d77 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "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.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dec595d --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From fc12e8df693bc4f31bf1500a3e89cdebb6a27fc2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 00:12:46 +0000 Subject: [PATCH 29/73] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0ce9756..dd2754f 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.0", "@stdlib/ndarray-shape": "^0.2.0", "@stdlib/slice-base-args2multislice": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/symbol-iterator": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" From 4961fc68c9452704d676592b24fb7759236770ce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 02:59:49 +0000 Subject: [PATCH 30/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6273 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f183ca6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index db23f43..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,c,y,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(c={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(c.writable=!u.readonly,c.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-1],T=f[E=g-2],O=-1,(x=o(g))[g-1]=null,e(y={},"next",V),e(y,"return",k),d&&e(y,d,z),y;function V(){var e,r,t;return O+=1,w||O>=F?{done:!0}:(e=x.slice(),r=p(x),t=(x[E]+1)%T,x[E]=t,0===t&&(x=j(f,"row-major",x,E-1,x)),{value:[e,l(b,r,!0,c.writable)],done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,c)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 82476f2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;42CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index dec595d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From da4bacb0898e047421d5a4c1b55fa8e5ce1fca6b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:00:31 +0000 Subject: [PATCH 31/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 42 files changed, 6210 insertions(+), 4573 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d03a52b..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3975369..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('1lR4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('1lR2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('1lR2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('1lRF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('1lRF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 89ac3c8..f183ca6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..00a30e3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,c,y,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(c={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(c.writable=!u.readonly,c.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-1],T=f[E=g-2],O=-1,(x=o(g))[g-1]=null,e(y={},"next",V),e(y,"return",k),d&&e(y,d,z),y;function V(){var e,r,t;return O+=1,w||O>=F?{done:!0}:(e=x.slice(),r=p(x),t=(x[E]+1)%T,x[E]=t,0===t&&(x=j(f,"row-major",x,E-1,x)),{value:[e,l(b,r,!0,c.writable)],done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,c)}}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82476f2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;42CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d3f2c26..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index dd2754f..027e376 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.0", - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-boolean": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.0", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-base-slice": "^0.2.0", - "@stdlib/ndarray-shape": "^0.2.0", - "@stdlib/slice-base-args2multislice": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/symbol-iterator": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.2.0", - "@stdlib/assert-is-iterator-like": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-slice": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "proxyquire": "^2.0.0", - "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.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..edfa7e1 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 92ad09e71f59c6f1d6de6d438d1a7eaa235a5179 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:44:29 +0000 Subject: [PATCH 32/73] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c3b8891..e832ce7 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.0-esm/index.mjs'; ``` #### nditerRowEntries( x\[, options] ) @@ -159,7 +159,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.0-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 0fb498391e7695daf1dbfffbbb665d940c267d87 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:44:30 +0000 Subject: [PATCH 33/73] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e832ce7..18c3275 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-row-entries/tags). For example, + ```javascript import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.0-esm/index.mjs'; ``` @@ -159,7 +164,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.0-esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 28ccbee233f8cc4777d1929cad57ffd23f70f483 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:06:47 +0000 Subject: [PATCH 34/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index 6e4cbe4..737269c 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 6722c24795514044bc5f6c9a49669d9327a72701 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:55:27 +0000 Subject: [PATCH 35/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6273 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f183ca6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 00a30e3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function v(b){var u,f,g,c,y,w,x,E,T,F,O;if(!s(b))throw new TypeError(h("invalid argument. First argument must be an ndarray. Value: `%s`.",b));if(c={writable:!1},arguments.length>1){if(!r(u=arguments[1]))throw new TypeError(h("invalid argument. Options argument must be an object. Value: `%s`.",u));if(i(u,"readonly")){if(!t(u.readonly))throw new TypeError(h("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",u.readonly));if(c.writable=!u.readonly,c.writable&&n(b))throw new Error(h("invalid option. Cannot write to read-only array."))}}if((g=(f=a(b)).length)<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return 0===(F=m(f))&&(w=!0),F/=f[g-1],T=f[E=g-2],O=-1,(x=o(g))[g-1]=null,e(y={},"next",V),e(y,"return",k),d&&e(y,d,z),y;function V(){var e,r,t;return O+=1,w||O>=F?{done:!0}:(e=x.slice(),r=p(x),t=(x[E]+1)%T,x[E]=t,0===t&&(x=j(f,"row-major",x,E-1,x)),{value:[e,l(b,r,!0,c.writable)],done:!1})}function k(e){return w=!0,arguments.length?{value:e,done:!0}:{done:!0}}function z(){return v(b,c)}}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 82476f2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value"],"mappings":";;42CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,+DAAgE,WAAYb,EAAQoB,WAGlH,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,oDAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAW,uFA+BtB,OA1BW,KADXH,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,OAAQuB,GAC3BD,EAAatB,EAAM,SAAUwB,GAGxBC,GACJH,EAAatB,EAAMyB,EAAgBC,GAE7B1B,EAQP,SAASuB,IACR,IAAII,EACAC,EACAC,EAEJ,OADAvB,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNyB,MAAQ,IAIVH,EAAUzB,EAAI6B,QAGdH,EAAII,EAAiB9B,GAGrB2B,GAAM3B,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQ0B,EACF,IAANA,IAEJ3B,EAAM+B,EAAoBpC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAGpD,CACNgC,MAAS,CAAEP,EAASI,EAAOpC,EAAGiC,GAAG,EAAM7B,EAAKW,WAC5CoB,MAAQ,GAET,CASD,SAASN,EAAKU,GAEb,OADAjC,GAAM,EACDU,UAAUC,OACP,CACNsB,MAASA,EACTJ,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASJ,IACR,OAAOhC,EAAkBC,EAAGI,EAC5B,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index edfa7e1..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f6083298780f5468b95fe5ac4b51accde4a6c1f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:55:55 +0000 Subject: [PATCH 36/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 42 files changed, 4875 insertions(+), 4568 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3975369..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('1lR4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('1lR2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('1lR2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('1lRF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('1lRF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 89ac3c8..f183ca6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1c423fd --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 737269c..ab04098 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.0", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-slice": "^0.2.0", - "@stdlib/ndarray-to-array": "^0.2.0", - "@stdlib/ndarray-zeros": "^0.2.0", - "proxyquire": "^2.0.0", - "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" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..95bfcb3 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 6ce19557e17bc7566c451399760618bcaae4216d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:30:13 +0000 Subject: [PATCH 37/73] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e8667b..c171f36 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.1-esm/index.mjs'; ``` #### nditerRowEntries( x\[, options] ) @@ -159,7 +159,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.1-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 371c1e98c132557518c2bd1652bbb3da83a3caef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:30:13 +0000 Subject: [PATCH 38/73] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c171f36..fe16674 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-row-entries/tags). For example, + ```javascript import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.1-esm/index.mjs'; ``` @@ -159,7 +164,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.1-esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From da7034e72ac67875d8d4a7d439d6aaf8546c5e8c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 07:52:49 +0000 Subject: [PATCH 39/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index 8f8331e..026791e 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 000aabf397b61b0d6cac0b7decce3f6d0c152b0c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:36:13 +0000 Subject: [PATCH 40/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f183ca6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1c423fd..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dad24db..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 95bfcb3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 825c36fcbd432d6a18d2ac85dcb23f92e010e32e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:36:32 +0000 Subject: [PATCH 41/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 43 files changed, 4875 insertions(+), 4570 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4523c3b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:41:10.844Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3975369..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('1lR4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('1lR2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('1lR2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('1lRF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('1lRF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 89ac3c8..f183ca6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7d5a382 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 026791e..ab04098 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "proxyquire": "^2.0.0", - "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" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d9cc021 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 80df0871863377335876644950a398f5f77c21de Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:10:38 +0000 Subject: [PATCH 42/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index 8f8331e..026791e 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 281cb8742ac0fbbf2f6a6c197f9243b6054cf06b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:30:37 +0000 Subject: [PATCH 43/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f183ca6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7d5a382..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dad24db..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d9cc021..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6db094b7f91b17e8cd447460df4f7e16563da66c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:30:53 +0000 Subject: [PATCH 44/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 43 files changed, 4875 insertions(+), 4573 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 12aa3d0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T04:59:25.556Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3975369..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('1lR4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('1lR2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('1lR2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('1lRF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('1lRF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 89ac3c8..f183ca6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7d5a382 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 026791e..ab04098 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "proxyquire": "^2.0.0", - "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" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d9cc021 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From d86230e7414e51914700c756a921591d0e360c0b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:28:18 +0000 Subject: [PATCH 45/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index 8f8331e..026791e 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 5146843727821d8607f5fbf3aeb8fdf42f413616 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:50:48 +0000 Subject: [PATCH 46/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f183ca6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7d5a382..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dad24db..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d9cc021..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8c28fcee0c8e775ee94c06a637862deaaade6bfd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:51:06 +0000 Subject: [PATCH 47/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 42 files changed, 4875 insertions(+), 4574 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.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 - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3975369..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){ -var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),T=require('@stdlib/assert-is-plain-object/dist'),F=require('@stdlib/assert-is-boolean/dist').isPrimitive,P=require('@stdlib/assert-is-ndarray-like/dist'),R=require('@stdlib/ndarray-base-assert-is-read-only/dist'),S=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),x=require('@stdlib/array-base-zeros/dist'),C=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),V=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v('1lR4f',a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v('1lR2V',r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v('1lR2o',"readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v('1lRF4'))}}if(i=C(a),n=i.length,n<2)throw new TypeError(v('1lRF2'));return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q -});var B=b();module.exports=B; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 89ac3c8..f183ca6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7d5a382 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 026791e..ab04098 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "proxyquire": "^2.0.0", - "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" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d9cc021 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From ed0286f920145df42e2b251f483d468d223b0810 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:45:23 +0000 Subject: [PATCH 48/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index bbef17f..cabdd49 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 2a5b863246144a2d5bbed52aafa4faf6af1f765d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:58:55 +0000 Subject: [PATCH 49/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f183ca6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7d5a382..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dad24db..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d9cc021..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 524cac68260655ae6ede46db6004569733cabfe8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:59:23 +0000 Subject: [PATCH 50/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 108 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 42 files changed, 4875 insertions(+), 4704 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f20c23a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),T=require("@stdlib/assert-is-plain-object"),F=require("@stdlib/assert-is-boolean").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),R=require("@stdlib/ndarray-base-assert-is-read-only"),S=require("@stdlib/assert-has-own-property"),p=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-zeros"),C=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),V=require("@stdlib/ndarray-base-slice"),k=require("@stdlib/ndarray-base-next-cartesian-index").assign,z=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(i=C(a),n=i.length,n<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q});var B=b();module.exports=B; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 89ac3c8..f183ca6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3e2fa0e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function f(b){var c,v,y,g,u,x,w,E,R,T,F;if(!t(b))throw new TypeError(h("1lR4f",b));if(g={writable:!1},arguments.length>1){if(!r(c=arguments[1]))throw new TypeError(h("1lR2V",c));if(i(c,"readonly")){if(!s(c.readonly))throw new TypeError(h("1lR2o","readonly",c.readonly));if(g.writable=!c.readonly,g.writable&&n(b))throw new Error(h("1lRF4"))}}if((y=(v=l(b)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(v))&&(x=!0),T/=v[y-1],R=v[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(v,"row-major",w,E-1,w));return{value:[e,a(b,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return f(b,g)})),u}export{f as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6b91e29 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;szCAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index cabdd49..30f3b36 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "proxyquire": "^2.0.0", - "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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..02e1c77 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From ebe87c7a663c88318104d9596dd2a5fc185805a5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:07:25 +0000 Subject: [PATCH 51/73] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a342af..6823e57 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.2-esm/index.mjs'; ``` #### nditerRowEntries( x\[, options] ) @@ -159,7 +159,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.2-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 94c34c8e2613dfdab9c40f4d3d0ad4f81905b806 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:07:25 +0000 Subject: [PATCH 52/73] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6823e57..9ae1029 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-row-entries/tags). For example, + ```javascript import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.2-esm/index.mjs'; ``` @@ -159,7 +164,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@v0.2.2-esm/index.mjs'; +import nditerRowEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-row-entries@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 7b0b4508904ecb4b3619ccb5f11bf7ee07f97d78 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 07:59:04 +0000 Subject: [PATCH 53/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index 7f19c23..397d3dd 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 7cd4ccbbe48085df285622f380862dd3104dee50 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:54:18 +0000 Subject: [PATCH 54/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f183ca6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3e2fa0e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function f(b){var c,v,y,g,u,x,w,E,R,T,F;if(!t(b))throw new TypeError(h("1lR4f",b));if(g={writable:!1},arguments.length>1){if(!r(c=arguments[1]))throw new TypeError(h("1lR2V",c));if(i(c,"readonly")){if(!s(c.readonly))throw new TypeError(h("1lR2o","readonly",c.readonly));if(g.writable=!c.readonly,g.writable&&n(b))throw new Error(h("1lRF4"))}}if((y=(v=l(b)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(v))&&(x=!0),T/=v[y-1],R=v[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(v,"row-major",w,E-1,w));return{value:[e,a(b,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return f(b,g)})),u}export{f as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6b91e29..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;szCAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 02e1c77..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4f70c967b6e26935b345b426e1c0b734c714c8cd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:54:43 +0000 Subject: [PATCH 55/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 78 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 43 files changed, 4875 insertions(+), 4675 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# 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/.keepalive b/.github/.keepalive deleted file mode 100644 index 6ff114d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T05:51:48.591Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f20c23a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),T=require("@stdlib/assert-is-plain-object"),F=require("@stdlib/assert-is-boolean").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),R=require("@stdlib/ndarray-base-assert-is-read-only"),S=require("@stdlib/assert-has-own-property"),p=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-zeros"),C=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),V=require("@stdlib/ndarray-base-slice"),k=require("@stdlib/ndarray-base-next-cartesian-index").assign,z=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(i=C(a),n=i.length,n<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q});var B=b();module.exports=B; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 89ac3c8..f183ca6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..689ec4c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index 397d3dd..30f3b36 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "proxyquire": "^2.0.0", - "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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..eb3fa23 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From aed50c156cf46a4d4516f18b86f860e12e5f5e72 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:22:50 +0000 Subject: [PATCH 56/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index eea56a3..dcf7ec5 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 5870072ea78fa39123f8fecb2675ce8dbcaa53f3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:50:23 +0000 Subject: [PATCH 57/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f183ca6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 689ec4c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dad24db..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index eb3fa23..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 57587c86c68f1fba3c4501a25f6defb4c14245e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:50:41 +0000 Subject: [PATCH 58/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 108 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 43 files changed, 4875 insertions(+), 4705 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# 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/.keepalive b/.github/.keepalive deleted file mode 100644 index 4116fcb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:18:35.268Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f20c23a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),T=require("@stdlib/assert-is-plain-object"),F=require("@stdlib/assert-is-boolean").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),R=require("@stdlib/ndarray-base-assert-is-read-only"),S=require("@stdlib/assert-has-own-property"),p=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-zeros"),C=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),V=require("@stdlib/ndarray-base-slice"),k=require("@stdlib/ndarray-base-next-cartesian-index").assign,z=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(i=C(a),n=i.length,n<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q});var B=b();module.exports=B; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 89ac3c8..f183ca6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..689ec4c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index dcf7ec5..30f3b36 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "proxyquire": "^2.0.0", - "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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..eb3fa23 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 859c5eaea24a358d680ace92242c83fdefb8939b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 18:16:36 +0000 Subject: [PATCH 59/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index eea56a3..dcf7ec5 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 7f8192c3eb10d63c226038611a5ca06b2166bafa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 18:26:33 +0000 Subject: [PATCH 60/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index f183ca6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 689ec4c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dad24db..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index eb3fa23..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7fb4049f31221290e6ab6368953031875d26e570 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 18:26:51 +0000 Subject: [PATCH 61/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 152 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 42 files changed, 4875 insertions(+), 4748 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f20c23a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),T=require("@stdlib/assert-is-plain-object"),F=require("@stdlib/assert-is-boolean").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),R=require("@stdlib/ndarray-base-assert-is-read-only"),S=require("@stdlib/assert-has-own-property"),p=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-zeros"),C=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),V=require("@stdlib/ndarray-base-slice"),k=require("@stdlib/ndarray-base-next-cartesian-index").assign,z=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(i=C(a),n=i.length,n<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q});var B=b();module.exports=B; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 569e099..4225c36 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..689ec4c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index dcf7ec5..30f3b36 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "proxyquire": "^2.0.0", - "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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..eb3fa23 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From eb424b37c5b6c7ed4be1fe81b8e3ca4d713701b1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:39:58 +0000 Subject: [PATCH 62/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index eea56a3..dcf7ec5 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From be17b60ffa5ec8061d896898d32cf292115b7916 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:22:09 +0000 Subject: [PATCH 63/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4225c36..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 689ec4c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dad24db..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index eb3fa23..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 841cbd54f5de80ad9cf899ff13fc1449ae2a1fcf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:22:26 +0000 Subject: [PATCH 64/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 152 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 43 files changed, 4875 insertions(+), 4749 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# 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/.keepalive b/.github/.keepalive deleted file mode 100644 index f833070..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:30:44.973Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f20c23a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),T=require("@stdlib/assert-is-plain-object"),F=require("@stdlib/assert-is-boolean").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),R=require("@stdlib/ndarray-base-assert-is-read-only"),S=require("@stdlib/assert-has-own-property"),p=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-zeros"),C=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),V=require("@stdlib/ndarray-base-slice"),k=require("@stdlib/ndarray-base-next-cartesian-index").assign,z=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(i=C(a),n=i.length,n<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q});var B=b();module.exports=B; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 569e099..4225c36 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..689ec4c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index dcf7ec5..30f3b36 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "proxyquire": "^2.0.0", - "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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..eb3fa23 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From f5ae7ee8718f088f89d5711a50bb6004a3b027de Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:26:56 +0000 Subject: [PATCH 65/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index eea56a3..dcf7ec5 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From f3c16e21393ccef242b3ee026e36d5734a618a8f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:27:08 +0000 Subject: [PATCH 66/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4225c36..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 689ec4c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dad24db..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index eb3fa23..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 747fca18dbb9802d8277519d76efedcc9aed2076 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:27:29 +0000 Subject: [PATCH 67/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 152 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 43 files changed, 4875 insertions(+), 4749 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# 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/.keepalive b/.github/.keepalive deleted file mode 100644 index fce7113..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:33:54.876Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f20c23a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),T=require("@stdlib/assert-is-plain-object"),F=require("@stdlib/assert-is-boolean").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),R=require("@stdlib/ndarray-base-assert-is-read-only"),S=require("@stdlib/assert-has-own-property"),p=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-zeros"),C=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),V=require("@stdlib/ndarray-base-slice"),k=require("@stdlib/ndarray-base-next-cartesian-index").assign,z=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(i=C(a),n=i.length,n<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q});var B=b();module.exports=B; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 569e099..4225c36 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..689ec4c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index dcf7ec5..30f3b36 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "proxyquire": "^2.0.0", - "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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..eb3fa23 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From a9d671cf8158710c6e8e7679aeb573d218a97588 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:43:16 +0000 Subject: [PATCH 68/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index d42071a..c0bd3ab 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 1a880dcc46659ded728bbb5a41d246f967bebd28 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:47:55 +0000 Subject: [PATCH 69/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4225c36..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 689ec4c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dad24db..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index eb3fa23..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5d490816da495c1338a530fc93d7f90fd2f20968 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:48:12 +0000 Subject: [PATCH 70/73] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 152 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 44 files changed, 4875 insertions(+), 4854 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# 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/.keepalive b/.github/.keepalive deleted file mode 100644 index 577a87c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T06:43:42.735Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b35b7f7..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f20c23a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),T=require("@stdlib/assert-is-plain-object"),F=require("@stdlib/assert-is-boolean").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),R=require("@stdlib/ndarray-base-assert-is-read-only"),S=require("@stdlib/assert-has-own-property"),p=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-zeros"),C=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),V=require("@stdlib/ndarray-base-slice"),k=require("@stdlib/ndarray-base-next-cartesian-index").assign,z=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(i=C(a),n=i.length,n<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q});var B=b();module.exports=B; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 569e099..4225c36 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..689ec4c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index c0bd3ab..30f3b36 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "proxyquire": "^2.0.0", - "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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..eb3fa23 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 0f4e0fee4a11e566acf052d2b249b7cf5dc1c252 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 21 Apr 2025 00:31:15 +0000 Subject: [PATCH 71/73] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index d3f2c26..3646288 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,7 +33,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var slice = require( '@stdlib/ndarray-base-slice' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -94,7 +94,7 @@ function nditerRowEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1lR4f', x ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerRowEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1lR2V', options ) ); } if ( hasOwnProp( options, 'readonly' ) ) { if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) ); + throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); } opts.writable = !options.readonly; if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); + throw new Error( format( '1lRF4' ) ); } } } @@ -120,7 +120,7 @@ function nditerRowEntries( x ) { // Ensure that the input array has sufficient dimensions... if ( ndims < 2 ) { - throw new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' ); + throw new TypeError( format('1lRF2') ); } // Check whether the input array is empty... diff --git a/package.json b/package.json index d42071a..c0bd3ab 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-slice": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From e527ec1f121bea15054bc7ea36e2a757b6d1108c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 21 Apr 2025 00:32:07 +0000 Subject: [PATCH 72/73] Remove files --- index.d.ts | 91 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4938 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4225c36..0000000 --- a/index.d.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether returned views should be read-only (default: true). - * - * ## Notes - * - * - If the input array is read-only, setting this option to `false` raises an exception. - */ - readonly?: boolean; -} - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). A dimension index equal to `null` indicates that all values along the respective dimension are included in the returned ndarray. -* -* @param x - input array -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -declare function nditerRowEntries( x: typedndarray, options?: Options ): Iterator<[ Array, typedndarray ]>; - - -// EXPORTS // - -export = nditerRowEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 689ec4c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index dad24db..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index eb3fa23..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fa092ab9310019530551697d218865c455c7695f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 21 Apr 2025 00:32:41 +0000 Subject: [PATCH 73/73] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 152 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 85 - examples/index.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 64 - lib/main.js | 226 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 632 --- 44 files changed, 4875 insertions(+), 4857 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# 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/.keepalive b/.github/.keepalive deleted file mode 100644 index 2319d94..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-21T00:30:35.822Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6818db8..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 7fad789..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2d16ab2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '45 21 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - 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' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -232,7 +223,7 @@ while ( true ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -297,17 +288,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries +[@stdlib/ndarray/iter/column-entries]: https://github.com/stdlib-js/ndarray-iter-column-entries/tree/esm -[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries +[@stdlib/ndarray/iter/entries]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows +[@stdlib/ndarray/iter/rows]: https://github.com/stdlib-js/ndarray-iter-rows/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d077d6e..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerRowEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ [ 1, 2, 3, 4 ] ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerRowEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerRowEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 4cff753..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/row-entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-row-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-row-entries/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 8d774f7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerRowEntries from '../docs/types/index'; -export = nditerRowEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f20c23a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var j=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var b=j(function(I,c){"use strict";var w=require("@stdlib/utils-define-nonenumerable-read-only-property"),T=require("@stdlib/assert-is-plain-object"),F=require("@stdlib/assert-is-boolean").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),R=require("@stdlib/ndarray-base-assert-is-read-only"),S=require("@stdlib/assert-has-own-property"),p=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-zeros"),C=require("@stdlib/ndarray-shape"),L=require("@stdlib/ndarray-base-numel"),V=require("@stdlib/ndarray-base-slice"),k=require("@stdlib/ndarray-base-next-cartesian-index").assign,z=require("@stdlib/slice-base-args2multislice"),v=require("@stdlib/string-format");function q(a){var r,i,n,t,o,d,e,u,y,s,m;if(!P(a))throw new TypeError(v("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(t={writable:!1},arguments.length>1){if(r=arguments[1],!T(r))throw new TypeError(v("invalid argument. Options argument must be an object. Value: `%s`.",r));if(S(r,"readonly")){if(!F(r.readonly))throw new TypeError(v("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",r.readonly));if(t.writable=!r.readonly,t.writable&&R(a))throw new Error(v("invalid option. Cannot write to read-only array."))}}if(i=C(a),n=i.length,n<2)throw new TypeError("invalid argument. First argument must be an ndarray having at least two dimensions.");return s=L(i),s===0&&(d=!0),s/=i[n-1],u=n-2,y=i[u],m=-1,e=x(n),e[n-1]=null,o={},w(o,"next",h),w(o,"return",E),p&&w(o,p,O),o;function h(){var l,g,f;return m+=1,d||m>=s?{done:!0}:(l=e.slice(),g=z(e),f=(e[u]+1)%y,e[u]=f,f===0&&(e=k(i,"row-major",e,u-1,e)),{value:[l,V(a,g,!0,t.writable)],done:!1})}function E(l){return d=!0,arguments.length?{value:l,done:!0}:{done:!0}}function O(){return q(a,t)}}c.exports=q});var B=b();module.exports=B; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 20e7376..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar slice = require( '@stdlib/ndarray-base-slice' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar args2multislice = require( '@stdlib/slice-base-args2multislice' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( 'invalid option. Cannot write to read-only array.' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an ndarray having at least two dimensions.' );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerRowEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @module @stdlib/ndarray-iter-row-entries\n*\n* @example\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\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,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA+C9C,SAASC,EAAkBC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACvB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAACf,EAAee,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKX,EAAYW,EAAS,UAAW,EAAI,CACxC,GAAK,CAACd,EAAWc,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWH,EAAQ,+DAAgE,WAAYG,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAI,EAAQT,EAAUO,CAAE,EACpBG,EAAQD,EAAM,OAGTC,EAAQ,EACZ,MAAM,IAAI,UAAW,qFAAsF,EAI5G,OAAAO,EAAIhB,EAAOQ,CAAM,EACZQ,IAAM,IACVJ,EAAM,IAGPI,GAAKR,EAAOC,EAAM,CAAE,EACpBK,EAAML,EAAQ,EACdM,EAAKP,EAAOM,CAAI,EAGhBG,EAAI,GAGJJ,EAAMf,EAAOW,CAAM,EAGnBI,EAAKJ,EAAM,CAAE,EAAI,KAGjBE,EAAO,CAAC,EACRpB,EAAaoB,EAAM,OAAQO,CAAK,EAChC3B,EAAaoB,EAAM,SAAUQ,CAAI,EAG5BtB,GACJN,EAAaoB,EAAMd,EAAgBuB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CACf,IAAIG,EACAC,EACAC,EAEJ,OADAN,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAUR,EAAI,MAAM,EAGpBS,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBM,EAAO,YAAaK,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAAS,CAAEQ,EAASpB,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,CAAE,EACvD,KAAQ,EACT,EACD,CASA,SAASS,EAAKK,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASJ,GAAU,CAClB,OAAOf,EAAkBC,EAAGI,CAAK,CAClC,CACD,CAKApB,EAAO,QAAUe,ICvKjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerRowEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "S1", "N", "i", "next", "end", "factory", "indices", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 2a98c03..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, row] pairs for each row in a - matrix (or stack of matrices). - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). A dimension index equal to `null` indicates that all - values along the respective dimension are included in the returned ndarray. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.readonly: boolean (optional) - Boolean indicating whether returned ndarray views should be read-only. - If the input ndarray is read-only, setting this option to `false` raises - an exception. Default: true. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value; - > v[ 0 ] - [ 0, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 1, 2 ] - > v = it.next().value; - > v[ 0 ] - [ 1, null ] - > {{alias:@stdlib/ndarray/to-array}}( v[ 1 ] ) - [ 3, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 50ef958..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerRowEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x ); // $ExpectType Iterator<[(number | null)[], typedndarray]> - nditerRowEntries( x, {} ); // $ExpectType Iterator<[(number | null)[], typedndarray]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerRowEntries( '123' ); // $ExpectError - nditerRowEntries( 123 ); // $ExpectError - nditerRowEntries( true ); // $ExpectError - nditerRowEntries( false ); // $ExpectError - nditerRowEntries( null ); // $ExpectError - nditerRowEntries( undefined ); // $ExpectError - nditerRowEntries( {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x ); // $ExpectError - - nditerRowEntries( '123', {} ); // $ExpectError - nditerRowEntries( 123, {} ); // $ExpectError - nditerRowEntries( true, {} ); // $ExpectError - nditerRowEntries( false, {} ); // $ExpectError - nditerRowEntries( null, {} ); // $ExpectError - nditerRowEntries( undefined, {} ); // $ExpectError - nditerRowEntries( {}, {} ); // $ExpectError - nditerRowEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, 'abc' ); // $ExpectError - nditerRowEntries( x, 123 ); // $ExpectError - nditerRowEntries( x, true ); // $ExpectError - nditerRowEntries( x, false ); // $ExpectError - nditerRowEntries( x, null ); // $ExpectError - nditerRowEntries( x, [] ); // $ExpectError - nditerRowEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is boolean... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries( x, { 'readonly': 'abc' } ); // $ExpectError - nditerRowEntries( x, { 'readonly': 123 } ); // $ExpectError - nditerRowEntries( x, { 'readonly': null } ); // $ExpectError - nditerRowEntries( x, { 'readonly': [] } ); // $ExpectError - nditerRowEntries( x, { 'readonly': {} } ); // $ExpectError - nditerRowEntries( x, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2, 2 ] ); - - nditerRowEntries(); // $ExpectError - nditerRowEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index ab66fec..0000000 --- a/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerRowEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, row] pairs: -var it = nditerRowEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value[ 0 ] ); - console.log( ndarray2array( v.value[ 1 ] ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 569e099..4225c36 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3c421dc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function v(f){var b,c,y,g,u,x,w,E,R,T,F;if(!t(f))throw new TypeError(h("1lR4f",f));if(g={writable:!1},arguments.length>1){if(!r(b=arguments[1]))throw new TypeError(h("1lR2V",b));if(i(b,"readonly")){if(!s(b.readonly))throw new TypeError(h("1lR2o","readonly",b.readonly));if(g.writable=!b.readonly,g.writable&&n(f))throw new Error(h("1lRF4"))}}if((y=(c=l(f)).length)<2)throw new TypeError(h("1lRF2"));return 0===(T=m(c))&&(x=!0),T/=c[y-1],R=c[E=y-2],F=-1,(w=o(y))[y-1]=null,e(u={},"next",(function(){var e,r,s;if(F+=1,x||F>=T)return{done:!0};e=w.slice(),r=p(w),s=(w[E]+1)%R,w[E]=s,0===s&&(w=j(c,"row-major",w,E-1,w));return{value:[e,a(f,r,!0,g.writable)],done:!1}})),e(u,"return",(function(e){if(x=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),d&&e(u,d,(function(){return v(f,g)})),u}export{v as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..dad24db --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isReadOnly from '@stdlib/ndarray-base-assert-is-read-only';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport slice from '@stdlib/ndarray-base-slice';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport args2multislice from '@stdlib/slice-base-args2multislice';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices).\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} first argument must have at least two dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import ndarray2array from '@stdlib/ndarray-to-array';\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerRowEntries( x );\n*\n* var v = iter.next().value;\n* // returns [...]\n*\n* var idx = v[ 0 ];\n* // returns [ 0, 0, null ]\n*\n* var row = ndarray2array( v[ 1 ] );\n* // returns [ 1, 2 ]\n*\n* v = iter.next().value;\n* // returns [...]\n*\n* idx = v[ 0 ];\n* // returns [ 0, 1, null ]\n*\n* row = ndarray2array( v[ 1 ] );\n* // returns [ 3, 4 ]\n*\n* // ...\n*/\nfunction nditerRowEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S1;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1lR4f', x ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1lR2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'readonly' ) ) {\n\t\t\tif ( !isBoolean( options.readonly ) ) {\n\t\t\t\tthrow new TypeError( format( '1lR2o', 'readonly', options.readonly ) );\n\t\t\t}\n\t\t\topts.writable = !options.readonly;\n\t\t\tif ( opts.writable && isReadOnly( x ) ) {\n\t\t\t\tthrow new Error( format( '1lRF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( ndims < 2 ) {\n\t\tthrow new TypeError( format('1lRF2') );\n\t}\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Compute the number of rows across all stacks of matrices:\n\tN /= shape[ ndims-1 ];\n\tdim = ndims - 2;\n\tS1 = shape[ dim ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Set the last element to `null` to indicate that we want a full \"slice\" for the last dimension:\n\tidx[ ndims-1 ] = null;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\tvar indices;\n\t\tvar s;\n\t\tvar j;\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\t// Cache the current state of the index array:\n\t\tindices = idx.slice();\n\n\t\t// Create a multi-slice for the current view:\n\t\ts = args2multislice( idx );\n\n\t\t// Update the index array:\n\t\tj = ( idx[ dim ] + 1 ) % S1;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next row entry:\n\t\treturn {\n\t\t\t'value': [ indices, slice( x, s, true, opts.writable ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerRowEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerRowEntries;\n"],"names":["nditerRowEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","S1","N","i","isndarrayLike","TypeError","format","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","indices","s","j","done","slice","args2multislice","nextCartesianIndex","value","iteratorSymbol"],"mappings":";;q3CAkFA,SAASA,EAAkBC,GAC1B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAKvC,GAHAI,EAAO,CACNW,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASb,IAEvC,GAAKkB,EAAYlB,EAAS,YAAe,CACxC,IAAMmB,EAAWnB,EAAQoB,UACxB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,WAAYb,EAAQoB,WAG3D,GADAjB,EAAKW,UAAYd,EAAQoB,SACpBjB,EAAKW,UAAYO,EAAYtB,GACjC,MAAM,IAAIuB,MAAOT,EAAQ,SAE1B,CACD,CAMD,IAHAX,GADAD,EAAQsB,EAAUxB,IACJiB,QAGD,EACZ,MAAM,IAAIJ,UAAWC,EAAO,UA+B7B,OA1BW,KADXJ,EAAIe,EAAOvB,MAEVI,GAAM,GAGPI,GAAKR,EAAOC,EAAM,GAElBM,EAAKP,EADLM,EAAML,EAAQ,GAIdQ,GAAK,GAGLJ,EAAMmB,EAAOvB,IAGRA,EAAM,GAAM,KAIjBwB,EADAtB,EAAO,CAAA,EACY,QAenB,WACC,IAAIuB,EACAC,EACAC,EAEJ,GADAnB,GAAK,EACAL,GAAOK,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVH,EAAUrB,EAAIyB,QAGdH,EAAII,EAAiB1B,GAGrBuB,GAAMvB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQsB,EACF,IAANA,IAEJvB,EAAM2B,EAAoBhC,EAAO,YAAaK,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAAS,CAAEP,EAASI,EAAOhC,EAAG6B,GAAG,EAAMzB,EAAKW,WAC5CgB,MAAQ,EAET,IA1CDJ,EAAatB,EAAM,UAmDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDU,UAAUC,OACd,MAAO,CACNkB,MAASA,EACTJ,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA3DIK,GACJT,EAAatB,EAAM+B,GAkEpB,WACC,OAAOrC,EAAkBC,EAAGI,EAC5B,IAlEMC,CAmER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1f95fd1..0000000 --- a/lib/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @module @stdlib/ndarray-iter-row-entries -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* var nditerRowEntries = require( '@stdlib/ndarray-iter-row-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 3646288..0000000 --- a/lib/main.js +++ /dev/null @@ -1,226 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var slice = require( '@stdlib/ndarray-base-slice' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, row]` pairs for each row in a matrix (or stack of matrices). -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} first argument must have at least two dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerRowEntries( x ); -* -* var v = iter.next().value; -* // returns [...] -* -* var idx = v[ 0 ]; -* // returns [ 0, 0, null ] -* -* var row = ndarray2array( v[ 1 ] ); -* // returns [ 1, 2 ] -* -* v = iter.next().value; -* // returns [...] -* -* idx = v[ 0 ]; -* // returns [ 0, 1, null ] -* -* row = ndarray2array( v[ 1 ] ); -* // returns [ 3, 4 ] -* -* // ... -*/ -function nditerRowEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S1; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1lR4f', x ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1lR2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( '1lR2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( '1lRF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( ndims < 2 ) { - throw new TypeError( format('1lRF2') ); - } - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of rows across all stacks of matrices: - N /= shape[ ndims-1 ]; - dim = ndims - 2; - S1 = shape[ dim ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Set the last element to `null` to indicate that we want a full "slice" for the last dimension: - idx[ ndims-1 ] = null; - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - var indices; - var s; - var j; - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Cache the current state of the index array: - indices = idx.slice(); - - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S1; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next row entry: - return { - 'value': [ indices, slice( x, s, true, opts.writable ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerRowEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerRowEntries; diff --git a/package.json b/package.json index c0bd3ab..30f3b36 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, row] pairs for each row in a matrix (or stack of matrices).", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-slice": "^0.2.2", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "proxyquire": "^2.0.0", - "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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..eb3fa23 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2dbf185..0000000 --- a/test/test.js +++ /dev/null @@ -1,632 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var slice = require( '@stdlib/ndarray-slice' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerRowEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerRowEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which is not a boolean', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( zeros( [ 2, 2 ] ), { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `readonly` option which equal to `false` when the input array is read-only', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var x = zeros( [ 2, 2 ], { - 'readonly': true - }); - nditerRowEntries( x, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than two dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerRowEntries( value, {} ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] ); - expected = [ - { - 'value': [ [ 0, null ], slice( x, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, null ], slice( x, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 2, null ], slice( x, 2, null ) ], - 'done': false - }, - { - 'value': [ [ 3, null ], slice( x, 3, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); - expected = [ - { - 'value': [ [ 0, 0, null ], slice( x, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, null ], slice( x, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, null ], slice( x, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, null ], slice( x, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports returning writable views (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf ); - expected = [ - { - 'value': [ [ 0, 0, 0, null ], slice( x, 0, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, null ], slice( x, 0, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, null ], slice( x, 0, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, null ], slice( x, 0, 1, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, null ], slice( x, 1, 0, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, null ], slice( x, 1, 0, 1, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, null ], slice( x, 1, 1, 0, null ) ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, null ], slice( x, 1, 1, 1, null ) ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x, { - 'readonly': false - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.deepEqual( r.value[ 0 ], e.value[ 0 ], 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value[ 1 ] ), ndarray2array( e.value[ 1 ] ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value[ 1 ] ), false, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerRowEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( isndarrayLike( r.value[ 1 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerRowEntries; - var it1; - var it2; - var v1; - var v2; - var x; - var i; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerRowEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - v1 = it1.next().value; - v2 = it2.next().value; - t.deepEqual( [ v1[ 0 ], ndarray2array( v1[ 1 ] ) ], [ v2[ 0 ], ndarray2array( v2[ 1 ] ) ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerRowEntries; - var it; - - nditerRowEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerRowEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -});