From fa25c760bba973d21b4515700c6ea2d6f190d05d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 11 Aug 2024 09:14:22 +0000 Subject: [PATCH 01/26] 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 42dd053..8621a39 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,7 +34,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 // @@ -91,10 +91,10 @@ function nditerSubarrays( x, ndims ) { 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', x ) ); } if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) ); + throw new TypeError( format( 'null45', ndims ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerSubarrays( x, ndims ) { if ( arguments.length > 2 ) { options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', 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', '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( 'nullF4' ) ); } } } diff --git a/package.json b/package.json index 9249bb3..3c9c381 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,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 1382959ec65efa04701d70fa571a0134b55334e0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 11 Aug 2024 09:20:36 +0000 Subject: [PATCH 02/26] 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 | 48 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 99 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 225 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 585 --- 42 files changed, 4872 insertions(+), 4583 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 cce9e55..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/subarrays) 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 77aa81e..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/subarrays) 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 72158c9..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: '0 0 * * 6' - - # 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 + + ```
@@ -216,7 +207,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]. @@ -281,9 +272,9 @@ 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
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 44d8417..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var nditerSubarrays = 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 = nditerSubarrays( x, 2 ); - 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 xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ xbuf.length, 1, 1 ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerSubarrays( x, 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( z ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 443c5c7..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/subarrays" -%% click B href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/subarrays -[production-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/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 0827e62..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSubarrays from '../docs/types/index'; -export = nditerSubarrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d3a9a66..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var P=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var h=P(function(M,b){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,j=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),V=require('@stdlib/ndarray-base-assert-is-read-only/dist'),x=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),C=require('@stdlib/array-base-zeros/dist'),I=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a,r){var t,o,v,l,m,i,n,w,u,d,e;if(!F(a))throw new TypeError(s('null4f',a));if(!j(r))throw new TypeError(s('null45',r));if(v={writable:!1},arguments.length>2){if(t=arguments[2],!S(t))throw new TypeError(s('null2V',t));if(x(t,"readonly")){if(!T(t.readonly))throw new TypeError(s('null2o',"readonly",t.readonly));if(v.writable=!t.readonly,v.writable&&V(a))throw new Error(s('nullF4'))}}if(o=I(a),u=o.length,u<=r)throw new TypeError(s("invalid argument. First argument must be an ndarray having at least %d dimensions.",r+1));for(d=L(o),d===0&&(m=!0),n=u-r-1,e=n+1;e=d?{done:!0}:(f=z(i),g=(i[n]+1)%w,i[n]=g,g===0&&(i=k(o,"row-major",i,n-1,i)),{value:R(a,f,!0,v.writable),done:!1})}function E(f){return m=!0,arguments.length?{value:f,done:!0}:{done:!0}}function O(){return q(a,r,v)}}b.exports=q -});var B=h();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 8b91337..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) 2024 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\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\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\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\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the matrices in the current stack, move on to the next set of matrices:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSubarrays;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 iterates over each subarray in a stack of subarrays.\n*\n* @module @stdlib/ndarray-iter-subarrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\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,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,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,EA2C9C,SAASC,EAAiBC,EAAGC,EAAQ,CACpC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACb,EAAmBc,CAAM,EAC9B,MAAM,IAAI,UAAWH,EAAQ,6EAA8EG,CAAM,CAAE,EAKpH,GAHAG,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjB,EAAeiB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKZ,EAAYY,EAAS,UAAW,EAAI,CACxC,GAAK,CAAChB,EAAWgB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAE,EAAK,SAAW,CAACF,EAAQ,SACpBE,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAK,EAAQV,EAAUO,CAAE,EACpBU,EAAIP,EAAM,OAGLO,GAAKT,EACT,MAAM,IAAI,UAAWH,EAAQ,qFAAsFG,EAAM,CAAE,CAAE,EAS9H,IANAU,EAAIjB,EAAOS,CAAM,EACZQ,IAAM,IACVL,EAAM,IAGPE,EAAME,EAAIT,EAAQ,EACZW,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,CAAE,EAQf,IANAH,EAAIN,EAAOK,CAAI,EAGfD,EAAMf,EAAOkB,CAAE,EAGTE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,CAAE,EAAI,KAGZ,OAAAA,EAAI,GAGJP,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQQ,CAAK,EAChC7B,EAAaqB,EAAM,SAAUS,CAAI,EAG5BvB,GACJP,EAAaqB,EAAMd,EAAgBwB,CAAQ,EAErCV,EAQP,SAASQ,GAAO,CACf,IAAIG,EACAC,EAGJ,OADAL,GAAK,EACAN,GAAOM,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBO,EAAO,YAAaI,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASU,EAAKI,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOhB,EAAiBC,EAAGC,EAAOG,CAAK,CACxC,CACD,CAKArB,EAAO,QAAUgB,IC5KjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isPositiveInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerSubarrays", "x", "ndims", "options", "shape", "opts", "iter", "FLG", "idx", "dim", "S", "M", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 918e770..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( x, ndims[, options] ) - Returns an iterator which iterates over each subarray in a stack of - subarrays. - - 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 ndarray for which to create the iterator. Must have at least - `ndims+1` dimensions. - - ndims: integer - Number of dimensions to stack. - - 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, 2 ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ [ 1, 2 ], [ 3, 4 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b92ba3c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 nditerSubarrays = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); // $ExpectType Iterator> - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSubarrays( 123, 2 ); // $ExpectError - nditerSubarrays( true, 2 ); // $ExpectError - nditerSubarrays( false, 2 ); // $ExpectError - nditerSubarrays( null, 2 ); // $ExpectError - nditerSubarrays( undefined, 2 ); // $ExpectError - nditerSubarrays( {}, 2 ); // $ExpectError - nditerSubarrays( [], 2 ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2 ); // $ExpectError - - nditerSubarrays( 123, 2, {} ); // $ExpectError - nditerSubarrays( true, 2, {} ); // $ExpectError - nditerSubarrays( false, 2, {} ); // $ExpectError - nditerSubarrays( null, 2, {} ); // $ExpectError - nditerSubarrays( undefined, 2, {} ); // $ExpectError - nditerSubarrays( {}, 2, {} ); // $ExpectError - nditerSubarrays( [], 2, {} ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 'abc' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 123 ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 'abc' } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 123 } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': null } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': [] } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': {} } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSubarrays(); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe223f0..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSubarrays = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSubarrays( x, 2 ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( ndarray2array( v.value ) ); -} 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 384d176..4844924 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..79f6aea --- /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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2288401 --- /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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the matrices in the current stack, move on to the next set of matrices:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index dfa432a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @module @stdlib/ndarray-iter-subarrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ - -// 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 8621a39..0000000 --- a/lib/main.js +++ /dev/null @@ -1,225 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays. -* -* @param {ndarray} x - input value -* @param {PositiveInteger} ndims - number of dimensions to stack -* @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 `ndims+1` dimensions -* @throws {TypeError} second argument must be a positive integer -* @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 array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -function nditerSubarrays( x, ndims ) { - var options; - var shape; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S; - var M; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'null45', ndims ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 2 ) { - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'nullF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - M = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( M <= ndims ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of subarrays across all stacks of subarrays: - dim = M - ndims - 1; - for ( i = dim+1; i < M; i++ ) { - N /= shape[ i ]; - } - S = shape[ dim ]; - - // Initialize an index array for generating slices: - idx = zeros( M ); - - // Set the last `ndims` elements to `null` to indicate that we want a full "slice" for the last `ndims` dimensions: - for ( i = dim+1; i < M; i++ ) { - idx[ i ] = null; - } - // Initialize a counter: - i = -1; - - // 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 s; - var j; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the matrices in the current stack, move on to the next set of matrices: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next slice: - return { - 'value': 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 nditerSubarrays( x, ndims, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSubarrays; diff --git a/package.json b/package.json index 3c9c381..6f5220c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each subarray in a stack of subarrays.", "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/assert-is-positive-integer": "^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-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..db3d15e --- /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 f108774..0000000 --- a/test/test.js +++ /dev/null @@ -1,585 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 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 nditerSubarrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSubarrays, '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, - {}, - [], - 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -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, - {}, - [], - 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { - var values; - var i; - - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 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() { - nditerSubarrays( zeros( [ 2, 2, 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, 2 ], { - 'readonly': true - }); - nditerSubarrays( x, 2, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -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': slice( x, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2, { - '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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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 = nditerSubarrays( x, 2 ); - 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 nditerSubarrays; - var it1; - var it2; - var x; - var i; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSubarrays( x, 2 ); - 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.shape[ 0 ]; i++ ) { - t.deepEqual( ndarray2array( it2.next().value ), ndarray2array( it1.next().value ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerSubarrays; - var it; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From c7d9d124797024a303576bf9512aeccb889cada6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 11 Aug 2024 09:52:18 +0000 Subject: [PATCH 03/26] 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 edf7ee2..df71124 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,7 +34,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 // @@ -91,10 +91,10 @@ function nditerSubarrays( x, ndims ) { 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', x ) ); } if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) ); + throw new TypeError( format( 'null45', ndims ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerSubarrays( x, ndims ) { if ( arguments.length > 2 ) { options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', 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', '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( 'nullF4' ) ); } } } diff --git a/package.json b/package.json index 9249bb3..3c9c381 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,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 ecebcfd94a61d060382827abc7199d130c1c3b41 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 11 Aug 2024 09:52:42 +0000 Subject: [PATCH 04/26] Remove files --- index.d.ts | 82 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4929 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 4844924..0000000 --- a/index.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @param x - input value -* @param ndims - number of dimensions to stack -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -declare function nditerSubarrays( x: typedndarray, ndims: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSubarrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f6aea..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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2288401..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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the matrices in the current stack, move on to the next set of matrices:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index db3d15e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4c92a2bd0224222c77666cded830634e302244cc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 11 Aug 2024 09:53:41 +0000 Subject: [PATCH 05/26] 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 | 49 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 99 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 225 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 585 --- 42 files changed, 4872 insertions(+), 4584 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 cce9e55..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/subarrays) 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 77aa81e..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/subarrays) 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 72158c9..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: '0 0 * * 6' - - # 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 + + ```
@@ -216,7 +207,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]. @@ -281,9 +272,9 @@ 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
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 44d8417..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var nditerSubarrays = 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 = nditerSubarrays( x, 2 ); - 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 xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ xbuf.length, 1, 1 ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerSubarrays( x, 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( z ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 443c5c7..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/subarrays" -%% click B href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/subarrays -[production-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/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 0827e62..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSubarrays from '../docs/types/index'; -export = nditerSubarrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d3a9a66..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var P=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var h=P(function(M,b){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,j=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),V=require('@stdlib/ndarray-base-assert-is-read-only/dist'),x=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),C=require('@stdlib/array-base-zeros/dist'),I=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a,r){var t,o,v,l,m,i,n,w,u,d,e;if(!F(a))throw new TypeError(s('null4f',a));if(!j(r))throw new TypeError(s('null45',r));if(v={writable:!1},arguments.length>2){if(t=arguments[2],!S(t))throw new TypeError(s('null2V',t));if(x(t,"readonly")){if(!T(t.readonly))throw new TypeError(s('null2o',"readonly",t.readonly));if(v.writable=!t.readonly,v.writable&&V(a))throw new Error(s('nullF4'))}}if(o=I(a),u=o.length,u<=r)throw new TypeError(s("invalid argument. First argument must be an ndarray having at least %d dimensions.",r+1));for(d=L(o),d===0&&(m=!0),n=u-r-1,e=n+1;e=d?{done:!0}:(f=z(i),g=(i[n]+1)%w,i[n]=g,g===0&&(i=k(o,"row-major",i,n-1,i)),{value:R(a,f,!0,v.writable),done:!1})}function E(f){return m=!0,arguments.length?{value:f,done:!0}:{done:!0}}function O(){return q(a,r,v)}}b.exports=q -});var B=h();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 a3f0291..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) 2024 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\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\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\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\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSubarrays;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 iterates over each subarray in a stack of subarrays.\n*\n* @module @stdlib/ndarray-iter-subarrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\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,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,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,EA2C9C,SAASC,EAAiBC,EAAGC,EAAQ,CACpC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACb,EAAmBc,CAAM,EAC9B,MAAM,IAAI,UAAWH,EAAQ,6EAA8EG,CAAM,CAAE,EAKpH,GAHAG,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjB,EAAeiB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKZ,EAAYY,EAAS,UAAW,EAAI,CACxC,GAAK,CAAChB,EAAWgB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAE,EAAK,SAAW,CAACF,EAAQ,SACpBE,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAK,EAAQV,EAAUO,CAAE,EACpBU,EAAIP,EAAM,OAGLO,GAAKT,EACT,MAAM,IAAI,UAAWH,EAAQ,qFAAsFG,EAAM,CAAE,CAAE,EAS9H,IANAU,EAAIjB,EAAOS,CAAM,EACZQ,IAAM,IACVL,EAAM,IAGPE,EAAME,EAAIT,EAAQ,EACZW,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,CAAE,EAQf,IANAH,EAAIN,EAAOK,CAAI,EAGfD,EAAMf,EAAOkB,CAAE,EAGTE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,CAAE,EAAI,KAGZ,OAAAA,EAAI,GAGJP,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQQ,CAAK,EAChC7B,EAAaqB,EAAM,SAAUS,CAAI,EAG5BvB,GACJP,EAAaqB,EAAMd,EAAgBwB,CAAQ,EAErCV,EAQP,SAASQ,GAAO,CACf,IAAIG,EACAC,EAGJ,OADAL,GAAK,EACAN,GAAOM,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBO,EAAO,YAAaI,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASU,EAAKI,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOhB,EAAiBC,EAAGC,EAAOG,CAAK,CACxC,CACD,CAKArB,EAAO,QAAUgB,IC5KjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isPositiveInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerSubarrays", "x", "ndims", "options", "shape", "opts", "iter", "FLG", "idx", "dim", "S", "M", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 918e770..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( x, ndims[, options] ) - Returns an iterator which iterates over each subarray in a stack of - subarrays. - - 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 ndarray for which to create the iterator. Must have at least - `ndims+1` dimensions. - - ndims: integer - Number of dimensions to stack. - - 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, 2 ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ [ 1, 2 ], [ 3, 4 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b92ba3c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 nditerSubarrays = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); // $ExpectType Iterator> - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSubarrays( 123, 2 ); // $ExpectError - nditerSubarrays( true, 2 ); // $ExpectError - nditerSubarrays( false, 2 ); // $ExpectError - nditerSubarrays( null, 2 ); // $ExpectError - nditerSubarrays( undefined, 2 ); // $ExpectError - nditerSubarrays( {}, 2 ); // $ExpectError - nditerSubarrays( [], 2 ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2 ); // $ExpectError - - nditerSubarrays( 123, 2, {} ); // $ExpectError - nditerSubarrays( true, 2, {} ); // $ExpectError - nditerSubarrays( false, 2, {} ); // $ExpectError - nditerSubarrays( null, 2, {} ); // $ExpectError - nditerSubarrays( undefined, 2, {} ); // $ExpectError - nditerSubarrays( {}, 2, {} ); // $ExpectError - nditerSubarrays( [], 2, {} ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 'abc' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 123 ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 'abc' } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 123 } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': null } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': [] } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': {} } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSubarrays(); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe223f0..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSubarrays = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSubarrays( x, 2 ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( ndarray2array( v.value ) ); -} 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 384d176..4844924 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..79f6aea --- /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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82e1908 --- /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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index dfa432a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @module @stdlib/ndarray-iter-subarrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ - -// 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 df71124..0000000 --- a/lib/main.js +++ /dev/null @@ -1,225 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays. -* -* @param {ndarray} x - input value -* @param {PositiveInteger} ndims - number of dimensions to stack -* @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 `ndims+1` dimensions -* @throws {TypeError} second argument must be a positive integer -* @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 array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -function nditerSubarrays( x, ndims ) { - var options; - var shape; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S; - var M; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'null45', ndims ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 2 ) { - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'nullF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - M = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( M <= ndims ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of subarrays across all stacks of subarrays: - dim = M - ndims - 1; - for ( i = dim+1; i < M; i++ ) { - N /= shape[ i ]; - } - S = shape[ dim ]; - - // Initialize an index array for generating slices: - idx = zeros( M ); - - // Set the last `ndims` elements to `null` to indicate that we want a full "slice" for the last `ndims` dimensions: - for ( i = dim+1; i < M; i++ ) { - idx[ i ] = null; - } - // Initialize a counter: - i = -1; - - // 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 s; - var j; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next slice: - return { - 'value': 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 nditerSubarrays( x, ndims, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSubarrays; diff --git a/package.json b/package.json index 3c9c381..6f5220c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each subarray in a stack of subarrays.", "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/assert-is-positive-integer": "^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-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..54a511b --- /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 f108774..0000000 --- a/test/test.js +++ /dev/null @@ -1,585 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 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 nditerSubarrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSubarrays, '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, - {}, - [], - 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -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, - {}, - [], - 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { - var values; - var i; - - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 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() { - nditerSubarrays( zeros( [ 2, 2, 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, 2 ], { - 'readonly': true - }); - nditerSubarrays( x, 2, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -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': slice( x, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2, { - '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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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 = nditerSubarrays( x, 2 ); - 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 nditerSubarrays; - var it1; - var it2; - var x; - var i; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSubarrays( x, 2 ); - 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.shape[ 0 ]; i++ ) { - t.deepEqual( ndarray2array( it2.next().value ), ndarray2array( it1.next().value ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerSubarrays; - var it; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 7094bed0c57f7d73838ffeaef55e4179ff572e41 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:22:32 +0000 Subject: [PATCH 06/26] 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 edf7ee2..df71124 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,7 +34,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 // @@ -91,10 +91,10 @@ function nditerSubarrays( x, ndims ) { 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', x ) ); } if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) ); + throw new TypeError( format( 'null45', ndims ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerSubarrays( x, ndims ) { if ( arguments.length > 2 ) { options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', 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', '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( 'nullF4' ) ); } } } diff --git a/package.json b/package.json index 32b142b..25efcf6 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,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 4da96c69a09e5e7af0761a90ce6c0398d49e002d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:46:22 +0000 Subject: [PATCH 07/26] Remove files --- index.d.ts | 82 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4929 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 4844924..0000000 --- a/index.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @param x - input value -* @param ndims - number of dimensions to stack -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -declare function nditerSubarrays( x: typedndarray, ndims: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSubarrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f6aea..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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 82e1908..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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 54a511b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 373935a5bce1879e3043fae3ccf4e9da1b2fd3a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:46:39 +0000 Subject: [PATCH 08/26] 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 | 49 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 99 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 225 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 585 --- 43 files changed, 4872 insertions(+), 4585 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 50c2c12..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:18:18.155Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cce9e55..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/subarrays) 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 77aa81e..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/subarrays) 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 72158c9..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: '0 0 * * 6' - - # 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 + + ```
@@ -216,7 +207,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]. @@ -281,9 +272,9 @@ 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
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 44d8417..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var nditerSubarrays = 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 = nditerSubarrays( x, 2 ); - 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 xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ xbuf.length, 1, 1 ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerSubarrays( x, 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( z ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 443c5c7..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/subarrays" -%% click B href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/subarrays -[production-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/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 0827e62..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSubarrays from '../docs/types/index'; -export = nditerSubarrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d006e26..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var P=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var h=P(function(M,b){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,j=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),V=require('@stdlib/ndarray-base-assert-is-read-only/dist'),x=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),C=require('@stdlib/array-base-zeros/dist'),I=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a,r){var t,o,v,l,m,i,n,w,u,d,e;if(!F(a))throw new TypeError(s('1zf4f',a));if(!j(r))throw new TypeError(s('1zf45',r));if(v={writable:!1},arguments.length>2){if(t=arguments[2],!S(t))throw new TypeError(s('1zf2V',t));if(x(t,"readonly")){if(!T(t.readonly))throw new TypeError(s('1zf2o',"readonly",t.readonly));if(v.writable=!t.readonly,v.writable&&V(a))throw new Error(s('1zfF4'))}}if(o=I(a),u=o.length,u<=r)throw new TypeError(s('1zfGa',r+1));for(d=L(o),d===0&&(m=!0),n=u-r-1,e=n+1;e=d?{done:!0}:(f=z(i),g=(i[n]+1)%w,i[n]=g,g===0&&(i=k(o,"row-major",i,n-1,i)),{value:R(a,f,!0,v.writable),done:!1})}function E(f){return m=!0,arguments.length?{value:f,done:!0}:{done:!0}}function O(){return q(a,r,v)}}b.exports=q -});var B=h();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 a3f0291..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) 2024 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\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\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\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\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSubarrays;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 iterates over each subarray in a stack of subarrays.\n*\n* @module @stdlib/ndarray-iter-subarrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\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,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,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,EA2C9C,SAASC,EAAiBC,EAAGC,EAAQ,CACpC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACb,EAAmBc,CAAM,EAC9B,MAAM,IAAI,UAAWH,EAAQ,6EAA8EG,CAAM,CAAE,EAKpH,GAHAG,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjB,EAAeiB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKZ,EAAYY,EAAS,UAAW,EAAI,CACxC,GAAK,CAAChB,EAAWgB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAE,EAAK,SAAW,CAACF,EAAQ,SACpBE,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAK,EAAQV,EAAUO,CAAE,EACpBU,EAAIP,EAAM,OAGLO,GAAKT,EACT,MAAM,IAAI,UAAWH,EAAQ,qFAAsFG,EAAM,CAAE,CAAE,EAS9H,IANAU,EAAIjB,EAAOS,CAAM,EACZQ,IAAM,IACVL,EAAM,IAGPE,EAAME,EAAIT,EAAQ,EACZW,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,CAAE,EAQf,IANAH,EAAIN,EAAOK,CAAI,EAGfD,EAAMf,EAAOkB,CAAE,EAGTE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,CAAE,EAAI,KAGZ,OAAAA,EAAI,GAGJP,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQQ,CAAK,EAChC7B,EAAaqB,EAAM,SAAUS,CAAI,EAG5BvB,GACJP,EAAaqB,EAAMd,EAAgBwB,CAAQ,EAErCV,EAQP,SAASQ,GAAO,CACf,IAAIG,EACAC,EAGJ,OADAL,GAAK,EACAN,GAAOM,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBO,EAAO,YAAaI,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASU,EAAKI,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOhB,EAAiBC,EAAGC,EAAOG,CAAK,CACxC,CACD,CAKArB,EAAO,QAAUgB,IC5KjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isPositiveInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerSubarrays", "x", "ndims", "options", "shape", "opts", "iter", "FLG", "idx", "dim", "S", "M", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 918e770..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( x, ndims[, options] ) - Returns an iterator which iterates over each subarray in a stack of - subarrays. - - 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 ndarray for which to create the iterator. Must have at least - `ndims+1` dimensions. - - ndims: integer - Number of dimensions to stack. - - 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, 2 ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ [ 1, 2 ], [ 3, 4 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b92ba3c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 nditerSubarrays = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); // $ExpectType Iterator> - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSubarrays( 123, 2 ); // $ExpectError - nditerSubarrays( true, 2 ); // $ExpectError - nditerSubarrays( false, 2 ); // $ExpectError - nditerSubarrays( null, 2 ); // $ExpectError - nditerSubarrays( undefined, 2 ); // $ExpectError - nditerSubarrays( {}, 2 ); // $ExpectError - nditerSubarrays( [], 2 ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2 ); // $ExpectError - - nditerSubarrays( 123, 2, {} ); // $ExpectError - nditerSubarrays( true, 2, {} ); // $ExpectError - nditerSubarrays( false, 2, {} ); // $ExpectError - nditerSubarrays( null, 2, {} ); // $ExpectError - nditerSubarrays( undefined, 2, {} ); // $ExpectError - nditerSubarrays( {}, 2, {} ); // $ExpectError - nditerSubarrays( [], 2, {} ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 'abc' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 123 ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 'abc' } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 123 } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': null } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': [] } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': {} } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSubarrays(); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe223f0..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSubarrays = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSubarrays( x, 2 ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( ndarray2array( v.value ) ); -} 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 384d176..4844924 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..79f6aea --- /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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82e1908 --- /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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index dfa432a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @module @stdlib/ndarray-iter-subarrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ - -// 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 df71124..0000000 --- a/lib/main.js +++ /dev/null @@ -1,225 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays. -* -* @param {ndarray} x - input value -* @param {PositiveInteger} ndims - number of dimensions to stack -* @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 `ndims+1` dimensions -* @throws {TypeError} second argument must be a positive integer -* @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 array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -function nditerSubarrays( x, ndims ) { - var options; - var shape; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S; - var M; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'null45', ndims ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 2 ) { - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'nullF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - M = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( M <= ndims ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of subarrays across all stacks of subarrays: - dim = M - ndims - 1; - for ( i = dim+1; i < M; i++ ) { - N /= shape[ i ]; - } - S = shape[ dim ]; - - // Initialize an index array for generating slices: - idx = zeros( M ); - - // Set the last `ndims` elements to `null` to indicate that we want a full "slice" for the last `ndims` dimensions: - for ( i = dim+1; i < M; i++ ) { - idx[ i ] = null; - } - // Initialize a counter: - i = -1; - - // 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 s; - var j; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next slice: - return { - 'value': 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 nditerSubarrays( x, ndims, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSubarrays; diff --git a/package.json b/package.json index 25efcf6..6f5220c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each subarray in a stack of subarrays.", "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/assert-is-positive-integer": "^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-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..54a511b --- /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 f108774..0000000 --- a/test/test.js +++ /dev/null @@ -1,585 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 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 nditerSubarrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSubarrays, '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, - {}, - [], - 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -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, - {}, - [], - 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { - var values; - var i; - - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 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() { - nditerSubarrays( zeros( [ 2, 2, 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, 2 ], { - 'readonly': true - }); - nditerSubarrays( x, 2, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -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': slice( x, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2, { - '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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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 = nditerSubarrays( x, 2 ); - 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 nditerSubarrays; - var it1; - var it2; - var x; - var i; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSubarrays( x, 2 ); - 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.shape[ 0 ]; i++ ) { - t.deepEqual( ndarray2array( it2.next().value ), ndarray2array( it1.next().value ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerSubarrays; - var it; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 98b231dc8e7f11001f403a658ab812627d81d656 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:39:52 +0000 Subject: [PATCH 09/26] 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 edf7ee2..df71124 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,7 +34,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 // @@ -91,10 +91,10 @@ function nditerSubarrays( x, ndims ) { 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', x ) ); } if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) ); + throw new TypeError( format( 'null45', ndims ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerSubarrays( x, ndims ) { if ( arguments.length > 2 ) { options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', 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', '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( 'nullF4' ) ); } } } diff --git a/package.json b/package.json index 32b142b..25efcf6 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,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 1977fa09784d95b0d1054face0dc87db9fe074c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:18:41 +0000 Subject: [PATCH 10/26] Remove files --- index.d.ts | 82 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4929 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 4844924..0000000 --- a/index.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @param x - input value -* @param ndims - number of dimensions to stack -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -declare function nditerSubarrays( x: typedndarray, ndims: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSubarrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f6aea..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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 82e1908..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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 54a511b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 05dec2678ea58d350e41ca687855e346227e0f03 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:19:01 +0000 Subject: [PATCH 11/26] 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 | 49 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 99 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 225 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 585 --- 43 files changed, 4872 insertions(+), 4585 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 07ddf12..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:30:27.796Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cce9e55..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/subarrays) 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 77aa81e..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/subarrays) 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 72158c9..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: '0 0 * * 6' - - # 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 + + ```
@@ -216,7 +207,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]. @@ -281,9 +272,9 @@ 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
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 44d8417..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var nditerSubarrays = 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 = nditerSubarrays( x, 2 ); - 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 xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ xbuf.length, 1, 1 ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerSubarrays( x, 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( z ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 443c5c7..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/subarrays" -%% click B href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/subarrays -[production-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/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 0827e62..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSubarrays from '../docs/types/index'; -export = nditerSubarrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d006e26..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var P=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var h=P(function(M,b){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,j=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),V=require('@stdlib/ndarray-base-assert-is-read-only/dist'),x=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),C=require('@stdlib/array-base-zeros/dist'),I=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a,r){var t,o,v,l,m,i,n,w,u,d,e;if(!F(a))throw new TypeError(s('1zf4f',a));if(!j(r))throw new TypeError(s('1zf45',r));if(v={writable:!1},arguments.length>2){if(t=arguments[2],!S(t))throw new TypeError(s('1zf2V',t));if(x(t,"readonly")){if(!T(t.readonly))throw new TypeError(s('1zf2o',"readonly",t.readonly));if(v.writable=!t.readonly,v.writable&&V(a))throw new Error(s('1zfF4'))}}if(o=I(a),u=o.length,u<=r)throw new TypeError(s('1zfGa',r+1));for(d=L(o),d===0&&(m=!0),n=u-r-1,e=n+1;e=d?{done:!0}:(f=z(i),g=(i[n]+1)%w,i[n]=g,g===0&&(i=k(o,"row-major",i,n-1,i)),{value:R(a,f,!0,v.writable),done:!1})}function E(f){return m=!0,arguments.length?{value:f,done:!0}:{done:!0}}function O(){return q(a,r,v)}}b.exports=q -});var B=h();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 a3f0291..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) 2024 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\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\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\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\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSubarrays;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 iterates over each subarray in a stack of subarrays.\n*\n* @module @stdlib/ndarray-iter-subarrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\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,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,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,EA2C9C,SAASC,EAAiBC,EAAGC,EAAQ,CACpC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACb,EAAmBc,CAAM,EAC9B,MAAM,IAAI,UAAWH,EAAQ,6EAA8EG,CAAM,CAAE,EAKpH,GAHAG,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjB,EAAeiB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKZ,EAAYY,EAAS,UAAW,EAAI,CACxC,GAAK,CAAChB,EAAWgB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAE,EAAK,SAAW,CAACF,EAAQ,SACpBE,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAK,EAAQV,EAAUO,CAAE,EACpBU,EAAIP,EAAM,OAGLO,GAAKT,EACT,MAAM,IAAI,UAAWH,EAAQ,qFAAsFG,EAAM,CAAE,CAAE,EAS9H,IANAU,EAAIjB,EAAOS,CAAM,EACZQ,IAAM,IACVL,EAAM,IAGPE,EAAME,EAAIT,EAAQ,EACZW,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,CAAE,EAQf,IANAH,EAAIN,EAAOK,CAAI,EAGfD,EAAMf,EAAOkB,CAAE,EAGTE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,CAAE,EAAI,KAGZ,OAAAA,EAAI,GAGJP,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQQ,CAAK,EAChC7B,EAAaqB,EAAM,SAAUS,CAAI,EAG5BvB,GACJP,EAAaqB,EAAMd,EAAgBwB,CAAQ,EAErCV,EAQP,SAASQ,GAAO,CACf,IAAIG,EACAC,EAGJ,OADAL,GAAK,EACAN,GAAOM,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBO,EAAO,YAAaI,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASU,EAAKI,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOhB,EAAiBC,EAAGC,EAAOG,CAAK,CACxC,CACD,CAKArB,EAAO,QAAUgB,IC5KjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isPositiveInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerSubarrays", "x", "ndims", "options", "shape", "opts", "iter", "FLG", "idx", "dim", "S", "M", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 918e770..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( x, ndims[, options] ) - Returns an iterator which iterates over each subarray in a stack of - subarrays. - - 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 ndarray for which to create the iterator. Must have at least - `ndims+1` dimensions. - - ndims: integer - Number of dimensions to stack. - - 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, 2 ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ [ 1, 2 ], [ 3, 4 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b92ba3c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 nditerSubarrays = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); // $ExpectType Iterator> - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSubarrays( 123, 2 ); // $ExpectError - nditerSubarrays( true, 2 ); // $ExpectError - nditerSubarrays( false, 2 ); // $ExpectError - nditerSubarrays( null, 2 ); // $ExpectError - nditerSubarrays( undefined, 2 ); // $ExpectError - nditerSubarrays( {}, 2 ); // $ExpectError - nditerSubarrays( [], 2 ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2 ); // $ExpectError - - nditerSubarrays( 123, 2, {} ); // $ExpectError - nditerSubarrays( true, 2, {} ); // $ExpectError - nditerSubarrays( false, 2, {} ); // $ExpectError - nditerSubarrays( null, 2, {} ); // $ExpectError - nditerSubarrays( undefined, 2, {} ); // $ExpectError - nditerSubarrays( {}, 2, {} ); // $ExpectError - nditerSubarrays( [], 2, {} ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 'abc' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 123 ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 'abc' } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 123 } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': null } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': [] } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': {} } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSubarrays(); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe223f0..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSubarrays = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSubarrays( x, 2 ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( ndarray2array( v.value ) ); -} 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 384d176..4844924 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..79f6aea --- /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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82e1908 --- /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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index dfa432a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @module @stdlib/ndarray-iter-subarrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ - -// 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 df71124..0000000 --- a/lib/main.js +++ /dev/null @@ -1,225 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays. -* -* @param {ndarray} x - input value -* @param {PositiveInteger} ndims - number of dimensions to stack -* @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 `ndims+1` dimensions -* @throws {TypeError} second argument must be a positive integer -* @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 array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -function nditerSubarrays( x, ndims ) { - var options; - var shape; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S; - var M; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'null45', ndims ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 2 ) { - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'nullF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - M = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( M <= ndims ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of subarrays across all stacks of subarrays: - dim = M - ndims - 1; - for ( i = dim+1; i < M; i++ ) { - N /= shape[ i ]; - } - S = shape[ dim ]; - - // Initialize an index array for generating slices: - idx = zeros( M ); - - // Set the last `ndims` elements to `null` to indicate that we want a full "slice" for the last `ndims` dimensions: - for ( i = dim+1; i < M; i++ ) { - idx[ i ] = null; - } - // Initialize a counter: - i = -1; - - // 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 s; - var j; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next slice: - return { - 'value': 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 nditerSubarrays( x, ndims, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSubarrays; diff --git a/package.json b/package.json index 25efcf6..6f5220c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each subarray in a stack of subarrays.", "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/assert-is-positive-integer": "^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-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..54a511b --- /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 f108774..0000000 --- a/test/test.js +++ /dev/null @@ -1,585 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 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 nditerSubarrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSubarrays, '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, - {}, - [], - 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -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, - {}, - [], - 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { - var values; - var i; - - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 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() { - nditerSubarrays( zeros( [ 2, 2, 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, 2 ], { - 'readonly': true - }); - nditerSubarrays( x, 2, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -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': slice( x, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2, { - '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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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 = nditerSubarrays( x, 2 ); - 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 nditerSubarrays; - var it1; - var it2; - var x; - var i; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSubarrays( x, 2 ); - 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.shape[ 0 ]; i++ ) { - t.deepEqual( ndarray2array( it2.next().value ), ndarray2array( it1.next().value ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerSubarrays; - var it; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 5fe828a96400af502a1ad27204ad5a32dce56166 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:26:24 +0000 Subject: [PATCH 12/26] 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 edf7ee2..df71124 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,7 +34,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 // @@ -91,10 +91,10 @@ function nditerSubarrays( x, ndims ) { 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', x ) ); } if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) ); + throw new TypeError( format( 'null45', ndims ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerSubarrays( x, ndims ) { if ( arguments.length > 2 ) { options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', 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', '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( 'nullF4' ) ); } } } diff --git a/package.json b/package.json index 32b142b..25efcf6 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,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 b1b57ce63812e7c3e590167963b05379d829dccf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:27:00 +0000 Subject: [PATCH 13/26] Remove files --- index.d.ts | 82 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4929 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 4844924..0000000 --- a/index.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @param x - input value -* @param ndims - number of dimensions to stack -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -declare function nditerSubarrays( x: typedndarray, ndims: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSubarrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f6aea..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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 82e1908..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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 54a511b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bf6de3c8541a1938bdace8f947030b4b76594b1b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:27:17 +0000 Subject: [PATCH 14/26] 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 | 49 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 99 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 225 - package.json | 74 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 585 --- 43 files changed, 4872 insertions(+), 4585 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 062000a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:33:37.667Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cce9e55..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/subarrays) 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 77aa81e..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/subarrays) 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 72158c9..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: '0 0 * * 6' - - # 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 + + ```
@@ -216,7 +207,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]. @@ -281,9 +272,9 @@ 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
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 44d8417..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var nditerSubarrays = 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 = nditerSubarrays( x, 2 ); - 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 xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ xbuf.length, 1, 1 ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerSubarrays( x, 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( z ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 443c5c7..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/subarrays" -%% click B href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/subarrays -[production-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/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 0827e62..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSubarrays from '../docs/types/index'; -export = nditerSubarrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d006e26..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var P=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var h=P(function(M,b){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,j=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),V=require('@stdlib/ndarray-base-assert-is-read-only/dist'),x=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),C=require('@stdlib/array-base-zeros/dist'),I=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a,r){var t,o,v,l,m,i,n,w,u,d,e;if(!F(a))throw new TypeError(s('1zf4f',a));if(!j(r))throw new TypeError(s('1zf45',r));if(v={writable:!1},arguments.length>2){if(t=arguments[2],!S(t))throw new TypeError(s('1zf2V',t));if(x(t,"readonly")){if(!T(t.readonly))throw new TypeError(s('1zf2o',"readonly",t.readonly));if(v.writable=!t.readonly,v.writable&&V(a))throw new Error(s('1zfF4'))}}if(o=I(a),u=o.length,u<=r)throw new TypeError(s('1zfGa',r+1));for(d=L(o),d===0&&(m=!0),n=u-r-1,e=n+1;e=d?{done:!0}:(f=z(i),g=(i[n]+1)%w,i[n]=g,g===0&&(i=k(o,"row-major",i,n-1,i)),{value:R(a,f,!0,v.writable),done:!1})}function E(f){return m=!0,arguments.length?{value:f,done:!0}:{done:!0}}function O(){return q(a,r,v)}}b.exports=q -});var B=h();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 a3f0291..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) 2024 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\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\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\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\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSubarrays;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 iterates over each subarray in a stack of subarrays.\n*\n* @module @stdlib/ndarray-iter-subarrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\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,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,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,EA2C9C,SAASC,EAAiBC,EAAGC,EAAQ,CACpC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACb,EAAmBc,CAAM,EAC9B,MAAM,IAAI,UAAWH,EAAQ,6EAA8EG,CAAM,CAAE,EAKpH,GAHAG,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjB,EAAeiB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKZ,EAAYY,EAAS,UAAW,EAAI,CACxC,GAAK,CAAChB,EAAWgB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAE,EAAK,SAAW,CAACF,EAAQ,SACpBE,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAK,EAAQV,EAAUO,CAAE,EACpBU,EAAIP,EAAM,OAGLO,GAAKT,EACT,MAAM,IAAI,UAAWH,EAAQ,qFAAsFG,EAAM,CAAE,CAAE,EAS9H,IANAU,EAAIjB,EAAOS,CAAM,EACZQ,IAAM,IACVL,EAAM,IAGPE,EAAME,EAAIT,EAAQ,EACZW,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,CAAE,EAQf,IANAH,EAAIN,EAAOK,CAAI,EAGfD,EAAMf,EAAOkB,CAAE,EAGTE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,CAAE,EAAI,KAGZ,OAAAA,EAAI,GAGJP,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQQ,CAAK,EAChC7B,EAAaqB,EAAM,SAAUS,CAAI,EAG5BvB,GACJP,EAAaqB,EAAMd,EAAgBwB,CAAQ,EAErCV,EAQP,SAASQ,GAAO,CACf,IAAIG,EACAC,EAGJ,OADAL,GAAK,EACAN,GAAOM,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBO,EAAO,YAAaI,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASU,EAAKI,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOhB,EAAiBC,EAAGC,EAAOG,CAAK,CACxC,CACD,CAKArB,EAAO,QAAUgB,IC5KjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isPositiveInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerSubarrays", "x", "ndims", "options", "shape", "opts", "iter", "FLG", "idx", "dim", "S", "M", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 918e770..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( x, ndims[, options] ) - Returns an iterator which iterates over each subarray in a stack of - subarrays. - - 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 ndarray for which to create the iterator. Must have at least - `ndims+1` dimensions. - - ndims: integer - Number of dimensions to stack. - - 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, 2 ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ [ 1, 2 ], [ 3, 4 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b92ba3c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 nditerSubarrays = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); // $ExpectType Iterator> - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSubarrays( 123, 2 ); // $ExpectError - nditerSubarrays( true, 2 ); // $ExpectError - nditerSubarrays( false, 2 ); // $ExpectError - nditerSubarrays( null, 2 ); // $ExpectError - nditerSubarrays( undefined, 2 ); // $ExpectError - nditerSubarrays( {}, 2 ); // $ExpectError - nditerSubarrays( [], 2 ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2 ); // $ExpectError - - nditerSubarrays( 123, 2, {} ); // $ExpectError - nditerSubarrays( true, 2, {} ); // $ExpectError - nditerSubarrays( false, 2, {} ); // $ExpectError - nditerSubarrays( null, 2, {} ); // $ExpectError - nditerSubarrays( undefined, 2, {} ); // $ExpectError - nditerSubarrays( {}, 2, {} ); // $ExpectError - nditerSubarrays( [], 2, {} ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 'abc' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 123 ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 'abc' } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 123 } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': null } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': [] } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': {} } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSubarrays(); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe223f0..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSubarrays = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSubarrays( x, 2 ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( ndarray2array( v.value ) ); -} 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 384d176..4844924 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..79f6aea --- /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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82e1908 --- /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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index dfa432a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @module @stdlib/ndarray-iter-subarrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ - -// 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 df71124..0000000 --- a/lib/main.js +++ /dev/null @@ -1,225 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays. -* -* @param {ndarray} x - input value -* @param {PositiveInteger} ndims - number of dimensions to stack -* @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 `ndims+1` dimensions -* @throws {TypeError} second argument must be a positive integer -* @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 array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -function nditerSubarrays( x, ndims ) { - var options; - var shape; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S; - var M; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'null45', ndims ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 2 ) { - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'nullF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - M = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( M <= ndims ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of subarrays across all stacks of subarrays: - dim = M - ndims - 1; - for ( i = dim+1; i < M; i++ ) { - N /= shape[ i ]; - } - S = shape[ dim ]; - - // Initialize an index array for generating slices: - idx = zeros( M ); - - // Set the last `ndims` elements to `null` to indicate that we want a full "slice" for the last `ndims` dimensions: - for ( i = dim+1; i < M; i++ ) { - idx[ i ] = null; - } - // Initialize a counter: - i = -1; - - // 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 s; - var j; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next slice: - return { - 'value': 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 nditerSubarrays( x, ndims, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSubarrays; diff --git a/package.json b/package.json index 25efcf6..6f5220c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each subarray in a stack of subarrays.", "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/assert-is-positive-integer": "^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-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..54a511b --- /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 f108774..0000000 --- a/test/test.js +++ /dev/null @@ -1,585 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 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 nditerSubarrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSubarrays, '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, - {}, - [], - 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -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, - {}, - [], - 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { - var values; - var i; - - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 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() { - nditerSubarrays( zeros( [ 2, 2, 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, 2 ], { - 'readonly': true - }); - nditerSubarrays( x, 2, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -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': slice( x, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2, { - '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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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 = nditerSubarrays( x, 2 ); - 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 nditerSubarrays; - var it1; - var it2; - var x; - var i; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSubarrays( x, 2 ); - 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.shape[ 0 ]; i++ ) { - t.deepEqual( ndarray2array( it2.next().value ), ndarray2array( it1.next().value ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerSubarrays; - var it; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From e8de1522522087d6bbbdcbd83331f15ba18f13c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:42:57 +0000 Subject: [PATCH 15/26] 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 edf7ee2..df71124 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,7 +34,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 // @@ -91,10 +91,10 @@ function nditerSubarrays( x, ndims ) { 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', x ) ); } if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) ); + throw new TypeError( format( 'null45', ndims ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerSubarrays( x, ndims ) { if ( arguments.length > 2 ) { options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', 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', '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( 'nullF4' ) ); } } } diff --git a/package.json b/package.json index 51ac52d..4493074 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,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 e7b5c9d514edb6b9481c3d82d190cfc732254eae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:51:01 +0000 Subject: [PATCH 16/26] Remove files --- index.d.ts | 82 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4929 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 4844924..0000000 --- a/index.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @param x - input value -* @param ndims - number of dimensions to stack -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -declare function nditerSubarrays( x: typedndarray, ndims: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSubarrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f6aea..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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 82e1908..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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 54a511b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 68a96e25c8cd4818c2b0c0d82aab4eb0ff064d18 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:51:20 +0000 Subject: [PATCH 17/26] 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 | 49 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 99 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 225 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 585 --- 44 files changed, 4872 insertions(+), 4690 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 c2cbd6b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T06:43:24.924Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cce9e55..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/subarrays) 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 77aa81e..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/subarrays) 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 72158c9..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: '0 0 * * 6' - - # 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 + + ```
@@ -216,7 +207,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]. @@ -281,9 +272,9 @@ 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
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 44d8417..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var nditerSubarrays = 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 = nditerSubarrays( x, 2 ); - 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 xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ xbuf.length, 1, 1 ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerSubarrays( x, 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( z ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 443c5c7..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/subarrays" -%% click B href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/subarrays -[production-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/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 0827e62..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSubarrays from '../docs/types/index'; -export = nditerSubarrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d006e26..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var P=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var h=P(function(M,b){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,j=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),V=require('@stdlib/ndarray-base-assert-is-read-only/dist'),x=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),C=require('@stdlib/array-base-zeros/dist'),I=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a,r){var t,o,v,l,m,i,n,w,u,d,e;if(!F(a))throw new TypeError(s('1zf4f',a));if(!j(r))throw new TypeError(s('1zf45',r));if(v={writable:!1},arguments.length>2){if(t=arguments[2],!S(t))throw new TypeError(s('1zf2V',t));if(x(t,"readonly")){if(!T(t.readonly))throw new TypeError(s('1zf2o',"readonly",t.readonly));if(v.writable=!t.readonly,v.writable&&V(a))throw new Error(s('1zfF4'))}}if(o=I(a),u=o.length,u<=r)throw new TypeError(s('1zfGa',r+1));for(d=L(o),d===0&&(m=!0),n=u-r-1,e=n+1;e=d?{done:!0}:(f=z(i),g=(i[n]+1)%w,i[n]=g,g===0&&(i=k(o,"row-major",i,n-1,i)),{value:R(a,f,!0,v.writable),done:!1})}function E(f){return m=!0,arguments.length?{value:f,done:!0}:{done:!0}}function O(){return q(a,r,v)}}b.exports=q -});var B=h();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 a3f0291..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) 2024 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\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\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\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\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSubarrays;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 iterates over each subarray in a stack of subarrays.\n*\n* @module @stdlib/ndarray-iter-subarrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\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,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,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,EA2C9C,SAASC,EAAiBC,EAAGC,EAAQ,CACpC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACb,EAAmBc,CAAM,EAC9B,MAAM,IAAI,UAAWH,EAAQ,6EAA8EG,CAAM,CAAE,EAKpH,GAHAG,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjB,EAAeiB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKZ,EAAYY,EAAS,UAAW,EAAI,CACxC,GAAK,CAAChB,EAAWgB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAE,EAAK,SAAW,CAACF,EAAQ,SACpBE,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAK,EAAQV,EAAUO,CAAE,EACpBU,EAAIP,EAAM,OAGLO,GAAKT,EACT,MAAM,IAAI,UAAWH,EAAQ,qFAAsFG,EAAM,CAAE,CAAE,EAS9H,IANAU,EAAIjB,EAAOS,CAAM,EACZQ,IAAM,IACVL,EAAM,IAGPE,EAAME,EAAIT,EAAQ,EACZW,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,CAAE,EAQf,IANAH,EAAIN,EAAOK,CAAI,EAGfD,EAAMf,EAAOkB,CAAE,EAGTE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,CAAE,EAAI,KAGZ,OAAAA,EAAI,GAGJP,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQQ,CAAK,EAChC7B,EAAaqB,EAAM,SAAUS,CAAI,EAG5BvB,GACJP,EAAaqB,EAAMd,EAAgBwB,CAAQ,EAErCV,EAQP,SAASQ,GAAO,CACf,IAAIG,EACAC,EAGJ,OADAL,GAAK,EACAN,GAAOM,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBO,EAAO,YAAaI,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASU,EAAKI,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOhB,EAAiBC,EAAGC,EAAOG,CAAK,CACxC,CACD,CAKArB,EAAO,QAAUgB,IC5KjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isPositiveInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerSubarrays", "x", "ndims", "options", "shape", "opts", "iter", "FLG", "idx", "dim", "S", "M", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 918e770..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( x, ndims[, options] ) - Returns an iterator which iterates over each subarray in a stack of - subarrays. - - 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 ndarray for which to create the iterator. Must have at least - `ndims+1` dimensions. - - ndims: integer - Number of dimensions to stack. - - 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, 2 ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ [ 1, 2 ], [ 3, 4 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b92ba3c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 nditerSubarrays = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); // $ExpectType Iterator> - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSubarrays( 123, 2 ); // $ExpectError - nditerSubarrays( true, 2 ); // $ExpectError - nditerSubarrays( false, 2 ); // $ExpectError - nditerSubarrays( null, 2 ); // $ExpectError - nditerSubarrays( undefined, 2 ); // $ExpectError - nditerSubarrays( {}, 2 ); // $ExpectError - nditerSubarrays( [], 2 ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2 ); // $ExpectError - - nditerSubarrays( 123, 2, {} ); // $ExpectError - nditerSubarrays( true, 2, {} ); // $ExpectError - nditerSubarrays( false, 2, {} ); // $ExpectError - nditerSubarrays( null, 2, {} ); // $ExpectError - nditerSubarrays( undefined, 2, {} ); // $ExpectError - nditerSubarrays( {}, 2, {} ); // $ExpectError - nditerSubarrays( [], 2, {} ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 'abc' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 123 ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 'abc' } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 123 } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': null } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': [] } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': {} } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSubarrays(); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe223f0..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSubarrays = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSubarrays( x, 2 ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( ndarray2array( v.value ) ); -} 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 384d176..4844924 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..79f6aea --- /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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82e1908 --- /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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index dfa432a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @module @stdlib/ndarray-iter-subarrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ - -// 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 df71124..0000000 --- a/lib/main.js +++ /dev/null @@ -1,225 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays. -* -* @param {ndarray} x - input value -* @param {PositiveInteger} ndims - number of dimensions to stack -* @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 `ndims+1` dimensions -* @throws {TypeError} second argument must be a positive integer -* @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 array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -function nditerSubarrays( x, ndims ) { - var options; - var shape; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S; - var M; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'null45', ndims ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 2 ) { - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'nullF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - M = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( M <= ndims ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of subarrays across all stacks of subarrays: - dim = M - ndims - 1; - for ( i = dim+1; i < M; i++ ) { - N /= shape[ i ]; - } - S = shape[ dim ]; - - // Initialize an index array for generating slices: - idx = zeros( M ); - - // Set the last `ndims` elements to `null` to indicate that we want a full "slice" for the last `ndims` dimensions: - for ( i = dim+1; i < M; i++ ) { - idx[ i ] = null; - } - // Initialize a counter: - i = -1; - - // 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 s; - var j; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next slice: - return { - 'value': 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 nditerSubarrays( x, ndims, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSubarrays; diff --git a/package.json b/package.json index 4493074..6f5220c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each subarray in a stack of subarrays.", "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/assert-is-positive-integer": "^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-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..54a511b --- /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 f108774..0000000 --- a/test/test.js +++ /dev/null @@ -1,585 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 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 nditerSubarrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSubarrays, '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, - {}, - [], - 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -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, - {}, - [], - 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { - var values; - var i; - - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 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() { - nditerSubarrays( zeros( [ 2, 2, 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, 2 ], { - 'readonly': true - }); - nditerSubarrays( x, 2, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -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': slice( x, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2, { - '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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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 = nditerSubarrays( x, 2 ); - 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 nditerSubarrays; - var it1; - var it2; - var x; - var i; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSubarrays( x, 2 ); - 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.shape[ 0 ]; i++ ) { - t.deepEqual( ndarray2array( it2.next().value ), ndarray2array( it1.next().value ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerSubarrays; - var it; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 50d64f5c3846bbf3052fdabeb864a070e8d454b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Jan 2025 10:02:02 +0000 Subject: [PATCH 18/26] 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 edf7ee2..df71124 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,7 +34,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 // @@ -91,10 +91,10 @@ function nditerSubarrays( x, ndims ) { 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', x ) ); } if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) ); + throw new TypeError( format( 'null45', ndims ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerSubarrays( x, ndims ) { if ( arguments.length > 2 ) { options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', 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', '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( 'nullF4' ) ); } } } diff --git a/package.json b/package.json index 51ac52d..4493074 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,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 40881645fda3195f810064cdb04f7d9c390d2587 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Jan 2025 10:06:04 +0000 Subject: [PATCH 19/26] Remove files --- index.d.ts | 82 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4929 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 4844924..0000000 --- a/index.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @param x - input value -* @param ndims - number of dimensions to stack -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -declare function nditerSubarrays( x: typedndarray, ndims: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSubarrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79f6aea..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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 82e1908..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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 54a511b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a6637e27c822ea1d69b8618fe11a8d2c420c2a50 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Jan 2025 10:06:20 +0000 Subject: [PATCH 20/26] 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 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 50 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 99 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 225 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 585 --- 43 files changed, 4876 insertions(+), 4694 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 .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 0779e8a..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 = 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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cce9e55..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/subarrays) 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 77aa81e..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/subarrays) 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 72158c9..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: '0 0 * * 6' - - # 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 + + ```
@@ -226,7 +217,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]. @@ -291,19 +282,19 @@ 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/columns]: https://github.com/stdlib-js/ndarray-iter-columns +[@stdlib/ndarray/iter/columns]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[@stdlib/ndarray/iter/matrices]: https://github.com/stdlib-js/ndarray-iter-matrices +[@stdlib/ndarray/iter/matrices]: https://github.com/stdlib-js/ndarray-iter-matrices/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 -[@stdlib/ndarray/iter/stacks]: https://github.com/stdlib-js/ndarray-iter-stacks +[@stdlib/ndarray/iter/stacks]: https://github.com/stdlib-js/ndarray-iter-stacks/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 44d8417..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var nditerSubarrays = 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 = nditerSubarrays( x, 2 ); - 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 xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ xbuf.length, 1, 1 ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerSubarrays( x, 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( z ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 443c5c7..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/subarrays" -%% click B href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/subarrays -[production-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/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 0827e62..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSubarrays from '../docs/types/index'; -export = nditerSubarrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d006e26..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var P=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var h=P(function(M,b){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,j=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),V=require('@stdlib/ndarray-base-assert-is-read-only/dist'),x=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),C=require('@stdlib/array-base-zeros/dist'),I=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a,r){var t,o,v,l,m,i,n,w,u,d,e;if(!F(a))throw new TypeError(s('1zf4f',a));if(!j(r))throw new TypeError(s('1zf45',r));if(v={writable:!1},arguments.length>2){if(t=arguments[2],!S(t))throw new TypeError(s('1zf2V',t));if(x(t,"readonly")){if(!T(t.readonly))throw new TypeError(s('1zf2o',"readonly",t.readonly));if(v.writable=!t.readonly,v.writable&&V(a))throw new Error(s('1zfF4'))}}if(o=I(a),u=o.length,u<=r)throw new TypeError(s('1zfGa',r+1));for(d=L(o),d===0&&(m=!0),n=u-r-1,e=n+1;e=d?{done:!0}:(f=z(i),g=(i[n]+1)%w,i[n]=g,g===0&&(i=k(o,"row-major",i,n-1,i)),{value:R(a,f,!0,v.writable),done:!1})}function E(f){return m=!0,arguments.length?{value:f,done:!0}:{done:!0}}function O(){return q(a,r,v)}}b.exports=q -});var B=h();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 a3f0291..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) 2024 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\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\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\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\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSubarrays;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 iterates over each subarray in a stack of subarrays.\n*\n* @module @stdlib/ndarray-iter-subarrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\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,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,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,EA2C9C,SAASC,EAAiBC,EAAGC,EAAQ,CACpC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACb,EAAmBc,CAAM,EAC9B,MAAM,IAAI,UAAWH,EAAQ,6EAA8EG,CAAM,CAAE,EAKpH,GAHAG,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjB,EAAeiB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKZ,EAAYY,EAAS,UAAW,EAAI,CACxC,GAAK,CAAChB,EAAWgB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAE,EAAK,SAAW,CAACF,EAAQ,SACpBE,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAK,EAAQV,EAAUO,CAAE,EACpBU,EAAIP,EAAM,OAGLO,GAAKT,EACT,MAAM,IAAI,UAAWH,EAAQ,qFAAsFG,EAAM,CAAE,CAAE,EAS9H,IANAU,EAAIjB,EAAOS,CAAM,EACZQ,IAAM,IACVL,EAAM,IAGPE,EAAME,EAAIT,EAAQ,EACZW,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,CAAE,EAQf,IANAH,EAAIN,EAAOK,CAAI,EAGfD,EAAMf,EAAOkB,CAAE,EAGTE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,CAAE,EAAI,KAGZ,OAAAA,EAAI,GAGJP,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQQ,CAAK,EAChC7B,EAAaqB,EAAM,SAAUS,CAAI,EAG5BvB,GACJP,EAAaqB,EAAMd,EAAgBwB,CAAQ,EAErCV,EAQP,SAASQ,GAAO,CACf,IAAIG,EACAC,EAGJ,OADAL,GAAK,EACAN,GAAOM,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBO,EAAO,YAAaI,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASU,EAAKI,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOhB,EAAiBC,EAAGC,EAAOG,CAAK,CACxC,CACD,CAKArB,EAAO,QAAUgB,IC5KjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isPositiveInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerSubarrays", "x", "ndims", "options", "shape", "opts", "iter", "FLG", "idx", "dim", "S", "M", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 918e770..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( x, ndims[, options] ) - Returns an iterator which iterates over each subarray in a stack of - subarrays. - - 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 ndarray for which to create the iterator. Must have at least - `ndims+1` dimensions. - - ndims: integer - Number of dimensions to stack. - - 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, 2 ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ [ 1, 2 ], [ 3, 4 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b92ba3c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 nditerSubarrays = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); // $ExpectType Iterator> - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSubarrays( 123, 2 ); // $ExpectError - nditerSubarrays( true, 2 ); // $ExpectError - nditerSubarrays( false, 2 ); // $ExpectError - nditerSubarrays( null, 2 ); // $ExpectError - nditerSubarrays( undefined, 2 ); // $ExpectError - nditerSubarrays( {}, 2 ); // $ExpectError - nditerSubarrays( [], 2 ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2 ); // $ExpectError - - nditerSubarrays( 123, 2, {} ); // $ExpectError - nditerSubarrays( true, 2, {} ); // $ExpectError - nditerSubarrays( false, 2, {} ); // $ExpectError - nditerSubarrays( null, 2, {} ); // $ExpectError - nditerSubarrays( undefined, 2, {} ); // $ExpectError - nditerSubarrays( {}, 2, {} ); // $ExpectError - nditerSubarrays( [], 2, {} ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 'abc' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 123 ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 'abc' } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 123 } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': null } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': [] } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': {} } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSubarrays(); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe223f0..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSubarrays = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSubarrays( x, 2 ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( ndarray2array( v.value ) ); -} 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 384d176..4844924 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..4b6a4c8 --- /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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82e1908 --- /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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index dfa432a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @module @stdlib/ndarray-iter-subarrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ - -// 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 df71124..0000000 --- a/lib/main.js +++ /dev/null @@ -1,225 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays. -* -* @param {ndarray} x - input value -* @param {PositiveInteger} ndims - number of dimensions to stack -* @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 `ndims+1` dimensions -* @throws {TypeError} second argument must be a positive integer -* @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 array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -function nditerSubarrays( x, ndims ) { - var options; - var shape; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S; - var M; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'null45', ndims ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 2 ) { - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'nullF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - M = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( M <= ndims ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of subarrays across all stacks of subarrays: - dim = M - ndims - 1; - for ( i = dim+1; i < M; i++ ) { - N /= shape[ i ]; - } - S = shape[ dim ]; - - // Initialize an index array for generating slices: - idx = zeros( M ); - - // Set the last `ndims` elements to `null` to indicate that we want a full "slice" for the last `ndims` dimensions: - for ( i = dim+1; i < M; i++ ) { - idx[ i ] = null; - } - // Initialize a counter: - i = -1; - - // 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 s; - var j; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next slice: - return { - 'value': 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 nditerSubarrays( x, ndims, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSubarrays; diff --git a/package.json b/package.json index 4493074..6f5220c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each subarray in a stack of subarrays.", "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/assert-is-positive-integer": "^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-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..54a511b --- /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 f108774..0000000 --- a/test/test.js +++ /dev/null @@ -1,585 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 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 nditerSubarrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSubarrays, '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, - {}, - [], - 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -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, - {}, - [], - 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { - var values; - var i; - - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 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() { - nditerSubarrays( zeros( [ 2, 2, 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, 2 ], { - 'readonly': true - }); - nditerSubarrays( x, 2, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -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': slice( x, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2, { - '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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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 = nditerSubarrays( x, 2 ); - 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 nditerSubarrays; - var it1; - var it2; - var x; - var i; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSubarrays( x, 2 ); - 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.shape[ 0 ]; i++ ) { - t.deepEqual( ndarray2array( it2.next().value ), ndarray2array( it1.next().value ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerSubarrays; - var it; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From eddd6e76635b5e3b953828ab7c2f6f6cb6ff84de Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 00:28:36 +0000 Subject: [PATCH 21/26] 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 edf7ee2..df71124 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,7 +34,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 // @@ -91,10 +91,10 @@ function nditerSubarrays( x, ndims ) { 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', x ) ); } if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) ); + throw new TypeError( format( 'null45', ndims ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerSubarrays( x, ndims ) { if ( arguments.length > 2 ) { options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', 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', '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( 'nullF4' ) ); } } } diff --git a/package.json b/package.json index 51ac52d..4493074 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,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 4a9fca10900030445f874030389af282f6d6a2f0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 00:33:38 +0000 Subject: [PATCH 22/26] Remove files --- index.d.ts | 82 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4929 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 4844924..0000000 --- a/index.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @param x - input value -* @param ndims - number of dimensions to stack -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -declare function nditerSubarrays( x: typedndarray, ndims: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSubarrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4b6a4c8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// 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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 82e1908..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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 54a511b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ca590dde4e22b96913852f1c9a855f1b87ebae9a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 00:34:29 +0000 Subject: [PATCH 23/26] 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 | 50 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 99 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 225 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 585 --- 44 files changed, 4876 insertions(+), 4698 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 cffe05f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-10T00:28:02.607Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3a8569d..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/subarrays) 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 77aa81e..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/subarrays) 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 72158c9..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: '0 0 * * 6' - - # 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 + + ```
@@ -226,7 +217,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]. @@ -291,19 +282,19 @@ 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/columns]: https://github.com/stdlib-js/ndarray-iter-columns +[@stdlib/ndarray/iter/columns]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[@stdlib/ndarray/iter/matrices]: https://github.com/stdlib-js/ndarray-iter-matrices +[@stdlib/ndarray/iter/matrices]: https://github.com/stdlib-js/ndarray-iter-matrices/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 -[@stdlib/ndarray/iter/stacks]: https://github.com/stdlib-js/ndarray-iter-stacks +[@stdlib/ndarray/iter/stacks]: https://github.com/stdlib-js/ndarray-iter-stacks/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 44d8417..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var nditerSubarrays = 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 = nditerSubarrays( x, 2 ); - 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 xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ xbuf.length, 1, 1 ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerSubarrays( x, 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( z ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 443c5c7..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/subarrays" -%% click B href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/subarrays -[production-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/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 0827e62..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSubarrays from '../docs/types/index'; -export = nditerSubarrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d006e26..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var P=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var h=P(function(M,b){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,j=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),V=require('@stdlib/ndarray-base-assert-is-read-only/dist'),x=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),C=require('@stdlib/array-base-zeros/dist'),I=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a,r){var t,o,v,l,m,i,n,w,u,d,e;if(!F(a))throw new TypeError(s('1zf4f',a));if(!j(r))throw new TypeError(s('1zf45',r));if(v={writable:!1},arguments.length>2){if(t=arguments[2],!S(t))throw new TypeError(s('1zf2V',t));if(x(t,"readonly")){if(!T(t.readonly))throw new TypeError(s('1zf2o',"readonly",t.readonly));if(v.writable=!t.readonly,v.writable&&V(a))throw new Error(s('1zfF4'))}}if(o=I(a),u=o.length,u<=r)throw new TypeError(s('1zfGa',r+1));for(d=L(o),d===0&&(m=!0),n=u-r-1,e=n+1;e=d?{done:!0}:(f=z(i),g=(i[n]+1)%w,i[n]=g,g===0&&(i=k(o,"row-major",i,n-1,i)),{value:R(a,f,!0,v.writable),done:!1})}function E(f){return m=!0,arguments.length?{value:f,done:!0}:{done:!0}}function O(){return q(a,r,v)}}b.exports=q -});var B=h();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 a3f0291..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) 2024 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\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\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\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\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSubarrays;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 iterates over each subarray in a stack of subarrays.\n*\n* @module @stdlib/ndarray-iter-subarrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\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,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,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,EA2C9C,SAASC,EAAiBC,EAAGC,EAAQ,CACpC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACb,EAAmBc,CAAM,EAC9B,MAAM,IAAI,UAAWH,EAAQ,6EAA8EG,CAAM,CAAE,EAKpH,GAHAG,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjB,EAAeiB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKZ,EAAYY,EAAS,UAAW,EAAI,CACxC,GAAK,CAAChB,EAAWgB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAE,EAAK,SAAW,CAACF,EAAQ,SACpBE,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAK,EAAQV,EAAUO,CAAE,EACpBU,EAAIP,EAAM,OAGLO,GAAKT,EACT,MAAM,IAAI,UAAWH,EAAQ,qFAAsFG,EAAM,CAAE,CAAE,EAS9H,IANAU,EAAIjB,EAAOS,CAAM,EACZQ,IAAM,IACVL,EAAM,IAGPE,EAAME,EAAIT,EAAQ,EACZW,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,CAAE,EAQf,IANAH,EAAIN,EAAOK,CAAI,EAGfD,EAAMf,EAAOkB,CAAE,EAGTE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,CAAE,EAAI,KAGZ,OAAAA,EAAI,GAGJP,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQQ,CAAK,EAChC7B,EAAaqB,EAAM,SAAUS,CAAI,EAG5BvB,GACJP,EAAaqB,EAAMd,EAAgBwB,CAAQ,EAErCV,EAQP,SAASQ,GAAO,CACf,IAAIG,EACAC,EAGJ,OADAL,GAAK,EACAN,GAAOM,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBO,EAAO,YAAaI,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASU,EAAKI,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOhB,EAAiBC,EAAGC,EAAOG,CAAK,CACxC,CACD,CAKArB,EAAO,QAAUgB,IC5KjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isPositiveInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerSubarrays", "x", "ndims", "options", "shape", "opts", "iter", "FLG", "idx", "dim", "S", "M", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 918e770..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( x, ndims[, options] ) - Returns an iterator which iterates over each subarray in a stack of - subarrays. - - 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 ndarray for which to create the iterator. Must have at least - `ndims+1` dimensions. - - ndims: integer - Number of dimensions to stack. - - 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, 2 ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ [ 1, 2 ], [ 3, 4 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b92ba3c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 nditerSubarrays = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); // $ExpectType Iterator> - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSubarrays( 123, 2 ); // $ExpectError - nditerSubarrays( true, 2 ); // $ExpectError - nditerSubarrays( false, 2 ); // $ExpectError - nditerSubarrays( null, 2 ); // $ExpectError - nditerSubarrays( undefined, 2 ); // $ExpectError - nditerSubarrays( {}, 2 ); // $ExpectError - nditerSubarrays( [], 2 ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2 ); // $ExpectError - - nditerSubarrays( 123, 2, {} ); // $ExpectError - nditerSubarrays( true, 2, {} ); // $ExpectError - nditerSubarrays( false, 2, {} ); // $ExpectError - nditerSubarrays( null, 2, {} ); // $ExpectError - nditerSubarrays( undefined, 2, {} ); // $ExpectError - nditerSubarrays( {}, 2, {} ); // $ExpectError - nditerSubarrays( [], 2, {} ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 'abc' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 123 ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 'abc' } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 123 } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': null } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': [] } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': {} } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSubarrays(); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe223f0..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSubarrays = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSubarrays( x, 2 ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( ndarray2array( v.value ) ); -} 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 384d176..4844924 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..4b6a4c8 --- /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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82e1908 --- /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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index dfa432a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @module @stdlib/ndarray-iter-subarrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ - -// 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 df71124..0000000 --- a/lib/main.js +++ /dev/null @@ -1,225 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays. -* -* @param {ndarray} x - input value -* @param {PositiveInteger} ndims - number of dimensions to stack -* @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 `ndims+1` dimensions -* @throws {TypeError} second argument must be a positive integer -* @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 array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -function nditerSubarrays( x, ndims ) { - var options; - var shape; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S; - var M; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'null45', ndims ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 2 ) { - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'nullF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - M = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( M <= ndims ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of subarrays across all stacks of subarrays: - dim = M - ndims - 1; - for ( i = dim+1; i < M; i++ ) { - N /= shape[ i ]; - } - S = shape[ dim ]; - - // Initialize an index array for generating slices: - idx = zeros( M ); - - // Set the last `ndims` elements to `null` to indicate that we want a full "slice" for the last `ndims` dimensions: - for ( i = dim+1; i < M; i++ ) { - idx[ i ] = null; - } - // Initialize a counter: - i = -1; - - // 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 s; - var j; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next slice: - return { - 'value': 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 nditerSubarrays( x, ndims, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSubarrays; diff --git a/package.json b/package.json index 4493074..6f5220c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each subarray in a stack of subarrays.", "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/assert-is-positive-integer": "^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-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..54a511b --- /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 f108774..0000000 --- a/test/test.js +++ /dev/null @@ -1,585 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 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 nditerSubarrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSubarrays, '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, - {}, - [], - 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -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, - {}, - [], - 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { - var values; - var i; - - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 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() { - nditerSubarrays( zeros( [ 2, 2, 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, 2 ], { - 'readonly': true - }); - nditerSubarrays( x, 2, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -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': slice( x, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2, { - '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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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 = nditerSubarrays( x, 2 ); - 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 nditerSubarrays; - var it1; - var it2; - var x; - var i; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSubarrays( x, 2 ); - 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.shape[ 0 ]; i++ ) { - t.deepEqual( ndarray2array( it2.next().value ), ndarray2array( it1.next().value ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerSubarrays; - var it; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 58ad0cfd493b7dac01790afdd6ba5ff9030c76ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Jun 2025 00:57:53 +0000 Subject: [PATCH 24/26] 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 edf7ee2..df71124 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,7 +34,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 // @@ -91,10 +91,10 @@ function nditerSubarrays( x, ndims ) { 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', x ) ); } if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) ); + throw new TypeError( format( 'null45', ndims ) ); } opts = { 'writable': false @@ -102,15 +102,15 @@ function nditerSubarrays( x, ndims ) { if ( arguments.length > 2 ) { options = arguments[ 2 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V', 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', '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( 'nullF4' ) ); } } } diff --git a/package.json b/package.json index 51ac52d..4493074 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,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 ef4c5e8adc4ea4dd2860d0a369bfc2dc3dcd7af2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Jun 2025 01:00:14 +0000 Subject: [PATCH 25/26] Remove files --- index.d.ts | 82 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4929 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 4844924..0000000 --- a/index.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @param x - input value -* @param ndims - number of dimensions to stack -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -declare function nditerSubarrays( x: typedndarray, ndims: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSubarrays; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4b6a4c8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// 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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 82e1908..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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 54a511b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8d31ee9f7f3ec8514b76a9bc5709eb9cc04250e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Jun 2025 01:00:54 +0000 Subject: [PATCH 26/26] 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 | 50 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 53 - docs/types/test.ts | 99 - examples/index.js | 42 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 225 - package.json | 74 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 585 --- 44 files changed, 4876 insertions(+), 4698 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 3e8dff0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-02T00:53:25.549Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3a8569d..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/subarrays) 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 77aa81e..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/subarrays) 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 72158c9..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: '0 0 * * 6' - - # 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 + + ```
@@ -226,7 +217,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]. @@ -291,19 +282,19 @@ 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/columns]: https://github.com/stdlib-js/ndarray-iter-columns +[@stdlib/ndarray/iter/columns]: https://github.com/stdlib-js/ndarray-iter-columns/tree/esm -[@stdlib/ndarray/iter/matrices]: https://github.com/stdlib-js/ndarray-iter-matrices +[@stdlib/ndarray/iter/matrices]: https://github.com/stdlib-js/ndarray-iter-matrices/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 -[@stdlib/ndarray/iter/stacks]: https://github.com/stdlib-js/ndarray-iter-stacks +[@stdlib/ndarray/iter/stacks]: https://github.com/stdlib-js/ndarray-iter-stacks/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 44d8417..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var nditerSubarrays = 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 = nditerSubarrays( x, 2 ); - 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 xbuf; - var iter; - var x; - var z; - var i; - - xbuf = []; - xbuf.length = b.iterations + 1; - x = array( xbuf, { - 'shape': [ xbuf.length, 1, 1 ], - 'dtype': 'generic', - 'copy': false - }); - - iter = nditerSubarrays( x, 2 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( z ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 443c5c7..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/subarrays" -%% click B href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/subarrays -[production-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-subarrays/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-subarrays/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 0827e62..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSubarrays from '../docs/types/index'; -export = nditerSubarrays; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d006e26..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var P=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var h=P(function(M,b){ -var y=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),S=require('@stdlib/assert-is-plain-object/dist'),T=require('@stdlib/assert-is-boolean/dist').isPrimitive,j=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,F=require('@stdlib/assert-is-ndarray-like/dist'),V=require('@stdlib/ndarray-base-assert-is-read-only/dist'),x=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),C=require('@stdlib/array-base-zeros/dist'),I=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-slice/dist'),k=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,z=require('@stdlib/slice-base-args2multislice/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function q(a,r){var t,o,v,l,m,i,n,w,u,d,e;if(!F(a))throw new TypeError(s('1zf4f',a));if(!j(r))throw new TypeError(s('1zf45',r));if(v={writable:!1},arguments.length>2){if(t=arguments[2],!S(t))throw new TypeError(s('1zf2V',t));if(x(t,"readonly")){if(!T(t.readonly))throw new TypeError(s('1zf2o',"readonly",t.readonly));if(v.writable=!t.readonly,v.writable&&V(a))throw new Error(s('1zfF4'))}}if(o=I(a),u=o.length,u<=r)throw new TypeError(s('1zfGa',r+1));for(d=L(o),d===0&&(m=!0),n=u-r-1,e=n+1;e=d?{done:!0}:(f=z(i),g=(i[n]+1)%w,i[n]=g,g===0&&(i=k(o,"row-major",i,n-1,i)),{value:R(a,f,!0,v.writable),done:!1})}function E(f){return m=!0,arguments.length?{value:f,done:!0}:{done:!0}}function O(){return q(a,r,v)}}b.exports=q -});var B=h();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 a3f0291..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) 2024 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\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\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\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\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSubarrays;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 iterates over each subarray in a stack of subarrays.\n*\n* @module @stdlib/ndarray-iter-subarrays\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\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,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,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,EA2C9C,SAASC,EAAiBC,EAAGC,EAAQ,CACpC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACb,EAAmBc,CAAM,EAC9B,MAAM,IAAI,UAAWH,EAAQ,6EAA8EG,CAAM,CAAE,EAKpH,GAHAG,EAAO,CACN,SAAY,EACb,EACK,UAAU,OAAS,EAAI,CAE3B,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjB,EAAeiB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKZ,EAAYY,EAAS,UAAW,EAAI,CACxC,GAAK,CAAChB,EAAWgB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAE,EAAK,SAAW,CAACF,EAAQ,SACpBE,EAAK,UAAYf,EAAYW,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACD,CAMA,GAJAK,EAAQV,EAAUO,CAAE,EACpBU,EAAIP,EAAM,OAGLO,GAAKT,EACT,MAAM,IAAI,UAAWH,EAAQ,qFAAsFG,EAAM,CAAE,CAAE,EAS9H,IANAU,EAAIjB,EAAOS,CAAM,EACZQ,IAAM,IACVL,EAAM,IAGPE,EAAME,EAAIT,EAAQ,EACZW,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,CAAE,EAQf,IANAH,EAAIN,EAAOK,CAAI,EAGfD,EAAMf,EAAOkB,CAAE,EAGTE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,CAAE,EAAI,KAGZ,OAAAA,EAAI,GAGJP,EAAO,CAAC,EACRrB,EAAaqB,EAAM,OAAQQ,CAAK,EAChC7B,EAAaqB,EAAM,SAAUS,CAAI,EAG5BvB,GACJP,EAAaqB,EAAMd,EAAgBwB,CAAQ,EAErCV,EAQP,SAASQ,GAAO,CACf,IAAIG,EACAC,EAGJ,OADAL,GAAK,EACAN,GAAOM,GAAKD,EACT,CACN,KAAQ,EACT,GAGDK,EAAInB,EAAiBU,CAAI,EAGzBU,GAAMV,EAAKC,CAAI,EAAI,GAAMC,EACzBF,EAAKC,CAAI,EAAIS,EACRA,IAAM,IAEVV,EAAMX,EAAoBO,EAAO,YAAaI,EAAKC,EAAI,EAAGD,CAAI,GAGxD,CACN,MAASZ,EAAOK,EAAGgB,EAAG,GAAMZ,EAAK,QAAS,EAC1C,KAAQ,EACT,EACD,CASA,SAASU,EAAKI,EAAQ,CAErB,OADAZ,EAAM,GACD,UAAU,OACP,CACN,MAASY,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASH,GAAU,CAClB,OAAOhB,EAAiBC,EAAGC,EAAOG,CAAK,CACxC,CACD,CAKArB,EAAO,QAAUgB,IC5KjB,IAAIoB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isPositiveInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "slice", "nextCartesianIndex", "args2multislice", "format", "nditerSubarrays", "x", "ndims", "options", "shape", "opts", "iter", "FLG", "idx", "dim", "S", "M", "N", "i", "next", "end", "factory", "s", "j", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 918e770..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,53 +0,0 @@ - -{{alias}}( x, ndims[, options] ) - Returns an iterator which iterates over each subarray in a stack of - subarrays. - - 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 ndarray for which to create the iterator. Must have at least - `ndims+1` dimensions. - - ndims: integer - Number of dimensions to stack. - - 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, 2 ); - > var v = it.next().value; - > {{alias:@stdlib/ndarray/to-array}}( v ) - [ [ 1, 2 ], [ 3, 4 ] ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b92ba3c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,99 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 nditerSubarrays = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); // $ExpectType Iterator> - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSubarrays( 123, 2 ); // $ExpectError - nditerSubarrays( true, 2 ); // $ExpectError - nditerSubarrays( false, 2 ); // $ExpectError - nditerSubarrays( null, 2 ); // $ExpectError - nditerSubarrays( undefined, 2 ); // $ExpectError - nditerSubarrays( {}, 2 ); // $ExpectError - nditerSubarrays( [], 2 ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2 ); // $ExpectError - - nditerSubarrays( 123, 2, {} ); // $ExpectError - nditerSubarrays( true, 2, {} ); // $ExpectError - nditerSubarrays( false, 2, {} ); // $ExpectError - nditerSubarrays( null, 2, {} ); // $ExpectError - nditerSubarrays( undefined, 2, {} ); // $ExpectError - nditerSubarrays( {}, 2, {} ); // $ExpectError - nditerSubarrays( [], 2, {} ); // $ExpectError - nditerSubarrays( ( x: number ): number => x, 2, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSubarrays( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 'abc' ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 123 ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, true ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, false ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, null ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, [] ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 'abc' } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': 123 } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': null } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': [] } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': {} } ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSubarrays(); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe223f0..0000000 --- a/examples/index.js +++ /dev/null @@ -1,42 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSubarrays = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSubarrays( x, 2 ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( ndarray2array( v.value ) ); -} 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 384d176..4844924 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..4b6a4c8 --- /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{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import{assign as p}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function f(b,u){var c,g,y,x,w,E,T,F,k,z,P;if(!n(b))throw new TypeError(v("null4f",b));if(!t(u))throw new TypeError(v("null45",u));if(y={writable:!1},arguments.length>2){if(!r(c=arguments[2]))throw new TypeError(v("null2V",c));if(d(c,"readonly")){if(!s(c.readonly))throw new TypeError(v("null2o","readonly",c.readonly));if(y.writable=!c.readonly,y.writable&&i(b))throw new Error(v("nullF4"))}}if((k=(g=m(b)).length)<=u)throw new TypeError(v("invalid argument. First argument must be an ndarray having at least %d dimensions.",u+1));for(0===(z=a(g))&&(w=!0),P=(T=k-u-1)+1;P=z)return{done:!0};e=h(E),r=(E[T]+1)%F,E[T]=r,0===r&&(E=p(g,"row-major",E,T-1,E));return{value:j(b,e,!0,y.writable),done:!1}})),e(x,"return",(function(e){if(w=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),o&&e(x,o,(function(){return f(b,u,y)})),x}export{f as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..82e1908 --- /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) 2024 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 { isPrimitive as isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 iterates over each subarray in a stack of subarrays.\n*\n* @param {ndarray} x - input value\n* @param {PositiveInteger} ndims - number of dimensions to stack\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 `ndims+1` dimensions\n* @throws {TypeError} second argument must be a positive integer\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 array from '@stdlib/ndarray-array';\n* import ndarray2array from '@stdlib/ndarray-to-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSubarrays( x, 2 );\n*\n* var v = iter.next().value;\n* // returns \n*\n* var arr = ndarray2array( v );\n* // returns [ [ 1, 2 ], [ 3, 4 ] ]\n*\n* v = iter.next().value;\n* // returns \n*\n* arr = ndarray2array( v );\n* // returns [ [ 5, 6 ], [ 7, 8 ] ]\n*\n* // ...\n*/\nfunction nditerSubarrays( x, ndims ) {\n\tvar options;\n\tvar shape;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar S;\n\tvar M;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isPositiveInteger( ndims ) ) {\n\t\tthrow new TypeError( format( 'null45', ndims ) );\n\t}\n\topts = {\n\t\t'writable': false\n\t};\n\tif ( arguments.length > 2 ) {\n\t\toptions = arguments[ 2 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V', 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', '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( 'nullF4' ) );\n\t\t\t}\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tM = shape.length;\n\n\t// Ensure that the input array has sufficient dimensions...\n\tif ( M <= ndims ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) );\n\t}\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 subarrays across all stacks of subarrays:\n\tdim = M - ndims - 1;\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tN /= shape[ i ];\n\t}\n\tS = shape[ dim ];\n\n\t// Initialize an index array for generating slices:\n\tidx = zeros( M );\n\n\t// Set the last `ndims` elements to `null` to indicate that we want a full \"slice\" for the last `ndims` dimensions:\n\tfor ( i = dim+1; i < M; i++ ) {\n\t\tidx[ i ] = null;\n\t}\n\t// Initialize a counter:\n\ti = -1;\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 s;\n\t\tvar j;\n\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// 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 ) % S;\n\t\tidx[ dim ] = j;\n\t\tif ( j === 0 ) {\n\t\t\t// If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays:\n\t\t\tidx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );\n\t\t}\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': 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 nditerSubarrays( x, ndims, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSubarrays;\n"],"names":["nditerSubarrays","x","ndims","options","shape","opts","iter","FLG","idx","dim","S","M","N","i","isndarrayLike","TypeError","format","isPositiveInteger","writable","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","numel","zeros","setReadOnly","s","j","done","args2multislice","nextCartesianIndex","value","slice","iteratorSymbol"],"mappings":";;y+CA+EA,SAASA,EAAiBC,EAAGC,GAC5B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeb,GACpB,MAAM,IAAIc,UAAWC,EAAQ,SAAUf,IAExC,IAAMgB,EAAmBf,GACxB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAKxC,GAHAG,EAAO,CACNa,UAAY,GAERC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIJ,UAAWC,EAAQ,SAAUb,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIT,UAAWC,EAAQ,SAAU,WAAYb,EAAQqB,WAG5D,GADAnB,EAAKa,UAAYf,EAAQqB,SACpBnB,EAAKa,UAAYO,EAAYxB,GACjC,MAAM,IAAIyB,MAAOV,EAAQ,UAE1B,CACD,CAMD,IAHAL,GADAP,EAAQuB,EAAU1B,IACRmB,SAGAlB,EACT,MAAM,IAAIa,UAAWC,EAAQ,qFAAsFd,EAAM,IAS1H,IALW,KADXU,EAAIgB,EAAOxB,MAEVG,GAAM,GAIDM,GADNJ,EAAME,EAAIT,EAAQ,GACJ,EAAGW,EAAIF,EAAGE,IACvBD,GAAKR,EAAOS,GAQb,IANAH,EAAIN,EAAOK,GAGXD,EAAMqB,EAAOlB,GAGPE,EAAIJ,EAAI,EAAGI,EAAIF,EAAGE,IACvBL,EAAKK,GAAM,KAcZ,OAXAA,GAAK,EAILiB,EADAxB,EAAO,CAAA,EACY,QAenB,WACC,IAAIyB,EACAC,EAGJ,GADAnB,GAAK,EACAN,GAAOM,GAAKD,EAChB,MAAO,CACNqB,MAAQ,GAIVF,EAAIG,EAAiB1B,GAGrBwB,GAAMxB,EAAKC,GAAQ,GAAMC,EACzBF,EAAKC,GAAQuB,EACF,IAANA,IAEJxB,EAAM2B,EAAoB/B,EAAO,YAAaI,EAAKC,EAAI,EAAGD,IAG3D,MAAO,CACN4B,MAASC,EAAOpC,EAAG8B,GAAG,EAAM1B,EAAKa,UACjCe,MAAQ,EAET,IAvCDH,EAAaxB,EAAM,UAgDnB,SAAc8B,GAEb,GADA7B,GAAM,EACDY,UAAUC,OACd,MAAO,CACNgB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAxDIK,GACJR,EAAaxB,EAAMgC,GA+DpB,WACC,OAAOtC,EAAiBC,EAAGC,EAAOG,EAClC,IA/DMC,CAgER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index dfa432a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 iterates over each subarray in a stack of subarrays. -* -* @module @stdlib/ndarray-iter-subarrays -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSubarrays = require( '@stdlib/ndarray-iter-subarrays' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ - -// 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 df71124..0000000 --- a/lib/main.js +++ /dev/null @@ -1,225 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 iterates over each subarray in a stack of subarrays. -* -* @param {ndarray} x - input value -* @param {PositiveInteger} ndims - number of dimensions to stack -* @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 `ndims+1` dimensions -* @throws {TypeError} second argument must be a positive integer -* @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 array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSubarrays( x, 2 ); -* -* var v = iter.next().value; -* // returns -* -* var arr = ndarray2array( v ); -* // returns [ [ 1, 2 ], [ 3, 4 ] ] -* -* v = iter.next().value; -* // returns -* -* arr = ndarray2array( v ); -* // returns [ [ 5, 6 ], [ 7, 8 ] ] -* -* // ... -*/ -function nditerSubarrays( x, ndims ) { - var options; - var shape; - var opts; - var iter; - var FLG; - var idx; - var dim; - var S; - var M; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isPositiveInteger( ndims ) ) { - throw new TypeError( format( 'null45', ndims ) ); - } - opts = { - 'writable': false - }; - if ( arguments.length > 2 ) { - options = arguments[ 2 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V', options ) ); - } - if ( hasOwnProp( options, 'readonly' ) ) { - if ( !isBoolean( options.readonly ) ) { - throw new TypeError( format( 'null2o', 'readonly', options.readonly ) ); - } - opts.writable = !options.readonly; - if ( opts.writable && isReadOnly( x ) ) { - throw new Error( format( 'nullF4' ) ); - } - } - } - // Retrieve input array meta data: - shape = getShape( x ); - M = shape.length; - - // Ensure that the input array has sufficient dimensions... - if ( M <= ndims ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray having at least %d dimensions.', ndims+1 ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of subarrays across all stacks of subarrays: - dim = M - ndims - 1; - for ( i = dim+1; i < M; i++ ) { - N /= shape[ i ]; - } - S = shape[ dim ]; - - // Initialize an index array for generating slices: - idx = zeros( M ); - - // Set the last `ndims` elements to `null` to indicate that we want a full "slice" for the last `ndims` dimensions: - for ( i = dim+1; i < M; i++ ) { - idx[ i ] = null; - } - // Initialize a counter: - i = -1; - - // 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 s; - var j; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Create a multi-slice for the current view: - s = args2multislice( idx ); - - // Update the index array: - j = ( idx[ dim ] + 1 ) % S; - idx[ dim ] = j; - if ( j === 0 ) { - // If we've iterated over all the subarrays in the current stack, move on to the next set of subarrays: - idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx ); - } - // Return the next slice: - return { - 'value': 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 nditerSubarrays( x, ndims, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSubarrays; diff --git a/package.json b/package.json index 4493074..6f5220c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each subarray in a stack of subarrays.", "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/assert-is-positive-integer": "^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-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..54a511b --- /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 f108774..0000000 --- a/test/test.js +++ /dev/null @@ -1,585 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 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 nditerSubarrays = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSubarrays, '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, - {}, - [], - 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -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, - {}, - [], - 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a positive integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { - var values; - var i; - - 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() { - nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2, 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() { - nditerSubarrays( zeros( [ 2, 2, 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, 2 ], { - 'readonly': true - }); - nditerSubarrays( x, 2, { - 'readonly': false - }); - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided an ndarray having fewer than `ndims+1` dimensions (options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [] ), - zeros( [ 2 ] ), - zeros( [ 2, 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() { - nditerSubarrays( value, 2, {} ); - }; - } -}); - -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': slice( x, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2 ); - 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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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': slice( x, 0, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 0, 1, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, 1, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSubarrays( x, 2, { - '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( isndarrayLike( r.value ), true, 'returns expected value' ); - t.deepEqual( ndarray2array( r.value ), ndarray2array( e.value ), 'returns expected value' ); - t.strictEqual( isReadOnly( r.value ), 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 = nditerSubarrays( x, 2 ); - 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isndarrayLike( r.value ), 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 nditerSubarrays; - var it1; - var it2; - var x; - var i; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSubarrays( x, 2 ); - 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.shape[ 0 ]; i++ ) { - t.deepEqual( ndarray2array( it2.next().value ), ndarray2array( it1.next().value ), 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerSubarrays; - var it; - - nditerSubarrays = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSubarrays( zeros( [ 2, 2, 2 ] ), 2 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -});