From 9632424c58ff10c77ce1f0da1bbf2505f735d54a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 11 Aug 2024 00:57:29 +0000 Subject: [PATCH 01/26] Transform error messages --- lib/main.js | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7d9a544..3c8710f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -35,7 +35,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var ndslice = require( '@stdlib/ndarray-base-slice' ); var Slice = require( '@stdlib/slice-ctor' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,10 +92,10 @@ function nditerSelectDimension( x, dim ) { 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 ( !isInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + throw new TypeError( format( 'null7f', dim ) ); } opts = { 'writable': false, @@ -104,20 +104,20 @@ function nditerSelectDimension( x, dim ) { 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' ) ); } } if ( hasOwnProp( options, 'keepdim' ) ) { if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) ); + throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); } opts.keepdim = options.keepdim; } @@ -129,7 +129,7 @@ function nditerSelectDimension( x, dim ) { // Normalize the dimension index: d = normalizeIndex( dim, ndims-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) ); + throw new RangeError( format( 'nullF8', ndims, dim ) ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index e1248ce..248bfc4 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 4ba060c7db3554b745e2d3368f5b3b4cc7f6985c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 11 Aug 2024 01:02:15 +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 | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - 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 | 224 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1093 ----- 42 files changed, 4875 insertions(+), 5116 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 342315d..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/select-dimension) 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 7a01fd4..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/select-dimension) 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 6963002..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 12 * * 2' - - # 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 + + ```
@@ -245,7 +236,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]. @@ -310,11 +301,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/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 d8e7344..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 nditerSelectDimension = 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 = nditerSelectDimension( x, 0 ); - 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 = nditerSelectDimension( x, 0 ); - - 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 9c014b1..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/select-dimension" -%% click B href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/select-dimension -[production-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/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 9c9336c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSelectDimension from '../docs/types/index'; -export = nditerSelectDimension; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 27e9aba..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var O=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var c=O(function(B,b){"use strict";var f=require("@stdlib/utils-define-nonenumerable-read-only-property"),S=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-is-boolean").isPrimitive,T=require("@stdlib/assert-is-integer").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),V=require("@stdlib/ndarray-base-assert-is-read-only"),g=require("@stdlib/assert-has-own-property"),y=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-filled"),R=require("@stdlib/ndarray-shape"),j=require("@stdlib/ndarray-base-normalize-index"),D=require("@stdlib/ndarray-base-numel"),F=require("@stdlib/ndarray-base-slice"),I=require("@stdlib/slice-ctor"),L=require("@stdlib/slice-base-args2multislice"),a=require("@stdlib/string-format");function q(i,r){var e,s,l,n,o,p,d,v,u,t;if(!P(i))throw new TypeError(a("invalid argument. First argument must be an ndarray. Value: `%s`.",i));if(!T(r))throw new TypeError(a("invalid argument. Second argument must be an integer. Value: `%s`.",r));if(n={writable:!1,keepdim:!1},arguments.length>2){if(e=arguments[2],!S(e))throw new TypeError(a("invalid argument. Options argument must be an object. Value: `%s`.",e));if(g(e,"readonly")){if(!w(e.readonly))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",e.readonly));if(n.writable=!e.readonly,n.writable&&V(i))throw new Error(a("invalid option. Cannot write to read-only array."))}if(g(e,"keepdim")){if(!w(e.keepdim))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","keepdim",e.keepdim));n.keepdim=e.keepdim}}if(s=R(i),l=s.length,u=j(r,l-1),u===-1)throw new RangeError(a("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",l,r));return v=D(s),v===0&&(p=!0),v=s[u],t=-1,d=x(null,l),o={},f(o,"next",h),f(o,"return",k),y&&f(o,y,E),o;function h(){var m;return t+=1,p||t>=v?{done:!0}:(n.keepdim?d[u]=new I(t,t+1,1):d[u]=t,m=L(d),{value:F(i,m,!0,n.writable),done:!1})}function k(m){return p=!0,arguments.length?{value:m,done:!0}:{done:!0}}function E(){return q(i,r,n)}}b.exports=q});var N=c();module.exports=N; -/** -* @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. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index cd682a1..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 isInteger = require( '@stdlib/assert-is-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 filled = require( '@stdlib/array-base-filled' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndslice = require( '@stdlib/ndarray-base-slice' );\nvar Slice = require( '@stdlib/slice-ctor' );\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\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 ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = filled( null, ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSelectDimension;\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 view along a specified dimension.\n*\n* @module @stdlib/ndarray-iter-select-dimension\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSelectDimension( x, 0 );\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,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAS,QAAS,2BAA4B,EAC9CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAU,QAAS,4BAA6B,EAChDC,EAAQ,QAAS,oBAAqB,EACtCC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA4C9C,SAASC,EAAuBC,EAAGC,EAAM,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACd,EAAWe,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAI,CAAE,EAM1G,GAJAI,EAAO,CACN,SAAY,GACZ,QAAW,EACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKb,EAAYa,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYjB,EAAYY,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACA,GAAKT,EAAYa,EAAS,SAAU,EAAI,CACvC,GAAK,CAACjB,EAAWiB,EAAQ,OAAQ,EAChC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAQ,OAAQ,CAAE,EAE3HG,EAAK,QAAUH,EAAQ,OACxB,CACD,CAOA,GALAC,EAAQX,EAAUQ,CAAE,EACpBI,EAAQD,EAAM,OAGdO,EAAIjB,EAAgBQ,EAAKG,EAAM,CAAE,EAC5BM,IAAM,GACV,MAAM,IAAI,WAAYZ,EAAQ,6GAA8GM,EAAOH,CAAI,CAAE,EAG1J,OAAAQ,EAAIf,EAAOS,CAAM,EACZM,IAAM,IACVF,EAAM,IAGPE,EAAIN,EAAOO,CAAE,EAGbC,EAAI,GAGJH,EAAMjB,EAAQ,KAAMa,CAAM,EAG1BE,EAAO,CAAC,EACRvB,EAAauB,EAAM,OAAQM,CAAK,EAChC7B,EAAauB,EAAM,SAAUO,CAAI,EAG5BvB,GACJP,EAAauB,EAAMhB,EAAgBwB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CACf,IAAIG,EAGJ,OADAJ,GAAK,EACAJ,GAAOI,GAAKF,EACT,CACN,KAAQ,EACT,GAGIJ,EAAK,QACTG,EAAKE,CAAE,EAAI,IAAId,EAAOe,EAAGA,EAAE,EAAG,CAAE,EAEhCH,EAAKE,CAAE,EAAIC,EAGZI,EAAIlB,EAAiBW,CAAI,EAGlB,CACN,MAASb,EAASK,EAAGe,EAAG,GAAMV,EAAK,QAAS,EAC5C,KAAQ,EACT,EACD,CASA,SAASQ,EAAKG,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOf,EAAuBC,EAAGC,EAAKI,CAAK,CAC5C,CACD,CAKAvB,EAAO,QAAUiB,IC3KjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "filled", "getShape", "normalizeIndex", "numel", "ndslice", "Slice", "args2multislice", "format", "nditerSelectDimension", "x", "dim", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "N", "d", "i", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 33d2556..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, dim[, options] ) - Returns an iterator which iterates over each view along a specified - dimension. - - 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. - - dim: integer - Dimension index. If less than zero, the index is resolved relative to - the last dimension, with the last dimension corresponding to the value - `-1`. - - 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. - - options.keepdim: boolean (optional) - Boolean indicating whether returned views should include the selected - dimension as a singleton dimension. Including the selected dimension as - a singleton dimension can be useful when wanting to ensure that returned - views remain broadcast compatible with the input ndarray. Default: - false. - - 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, 0 ); - > 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 ecb7b9d..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 nditerSelectDimension = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); // $ExpectType Iterator> - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSelectDimension( 123, 0 ); // $ExpectError - nditerSelectDimension( true, 0 ); // $ExpectError - nditerSelectDimension( false, 0 ); // $ExpectError - nditerSelectDimension( null, 0 ); // $ExpectError - nditerSelectDimension( undefined, 0 ); // $ExpectError - nditerSelectDimension( {}, 0 ); // $ExpectError - nditerSelectDimension( [], 0 ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0 ); // $ExpectError - - nditerSelectDimension( 123, 0, {} ); // $ExpectError - nditerSelectDimension( true, 0, {} ); // $ExpectError - nditerSelectDimension( false, 0, {} ); // $ExpectError - nditerSelectDimension( null, 0, {} ); // $ExpectError - nditerSelectDimension( undefined, 0, {} ); // $ExpectError - nditerSelectDimension( {}, 0, {} ); // $ExpectError - nditerSelectDimension( [], 0, {} ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSelectDimension( 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... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 'abc' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 123 ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 'abc' } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 123 } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': null } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': [] } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': {} } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSelectDimension(); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 872011c..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 nditerSelectDimension = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSelectDimension( x, 0 ); - -// 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 5acbfd8..d5d7768 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..25070e6 --- /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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.2-esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=m(null,w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),l&&e(k,l,(function(){return b(c,u,x)})),k}export{b as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b9076f9 --- /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 isInteger } from '@stdlib/assert-is-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 filled from '@stdlib/array-base-filled';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = filled( null, ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","filled","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;uiDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAQ,KAAM1B,GAIpB2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 766d309..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 view along a specified dimension. -* -* @module @stdlib/ndarray-iter-select-dimension -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSelectDimension( x, 0 ); -* -* 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 3c8710f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +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 isInteger = require( '@stdlib/assert-is-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 filled = require( '@stdlib/array-base-filled' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndslice = require( '@stdlib/ndarray-base-slice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param {ndarray} x - input value -* @param {integer} dim - dimension index -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} second argument must be an integer -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x, dim ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var N; - var d; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isInteger( dim ) ) { - throw new TypeError( format( 'null7f', dim ) ); - } - opts = { - 'writable': false, - 'keepdim': 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' ) ); - } - } - if ( hasOwnProp( options, 'keepdim' ) ) { - if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); - } - opts.keepdim = options.keepdim; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Normalize the dimension index: - d = normalizeIndex( dim, ndims-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'nullF8', ndims, dim ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of views (i.e., the dimension size): - N = shape[ d ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = filled( null, ndims ); - - // 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; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Update the index array to generate the next view: - if ( opts.keepdim ) { - idx[ d ] = new Slice( i, i+1, 1 ); - } else { - idx[ d ] = i; - } - // Create a multi-slice for the next view: - s = args2multislice( idx ); - - // Return the next slice: - return { - 'value': ndslice( 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 nditerSelectDimension( x, dim, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSelectDimension; diff --git a/package.json b/package.json index 248bfc4..a15ba47 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each view along a specified dimension.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-normalize-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/slice-ctor": "^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..55072d5 --- /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 58efa84..0000000 --- a/test/test.js +++ /dev/null @@ -1,1093 +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 Slice = require( '@stdlib/slice-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSelectDimension = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSelectDimension, '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() { - nditerSelectDimension( value, 0 ); - }; - } -}); - -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() { - nditerSelectDimension( value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds (options)', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `keepdim` 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'keepdim': 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 - }); - nditerSelectDimension( x, 0, { - 'readonly': false - }); - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=default)', 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 = nditerSelectDimension( x, 0 ); - 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=3, dim=0, keepdim=false)', 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 = nditerSelectDimension( x, 0, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=true)', 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, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 0, { - 'keepdim': true - }); - 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=3, dim=1, keepdim=default)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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=3, dim=1, keepdim=false)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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=3, dim=2, keepdim=default)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( 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=3, dim=2, keepdim=false)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=2, keepdim=true)', 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, null, null, new Slice( 0, 1 ) ), - 'done': false - }, - { - 'value': slice( x, null, null, new Slice( 1, 2 ) ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': true - }); - 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, dim=1, keepdim=default)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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, dim=1, keepdim=false)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), 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, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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, dim=1)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - '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 = nditerSelectDimension( x, 0 ); - 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' ); - } - - it = nditerSelectDimension( x, 1 ); - 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' ); - } - - it = nditerSelectDimension( 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 nditerSelectDimension; - var it1; - var it2; - var x; - var i; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSelectDimension( x, 0 ); - 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 nditerSelectDimension; - var it; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 583c9b83cdbffcab815013f20b2c77125b0b8b94 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:22:41 +0000 Subject: [PATCH 03/26] Transform error messages --- lib/main.js | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7d9a544..3c8710f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -35,7 +35,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var ndslice = require( '@stdlib/ndarray-base-slice' ); var Slice = require( '@stdlib/slice-ctor' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,10 +92,10 @@ function nditerSelectDimension( x, dim ) { 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 ( !isInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + throw new TypeError( format( 'null7f', dim ) ); } opts = { 'writable': false, @@ -104,20 +104,20 @@ function nditerSelectDimension( x, dim ) { 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' ) ); } } if ( hasOwnProp( options, 'keepdim' ) ) { if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) ); + throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); } opts.keepdim = options.keepdim; } @@ -129,7 +129,7 @@ function nditerSelectDimension( x, dim ) { // Normalize the dimension index: d = normalizeIndex( dim, ndims-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) ); + throw new RangeError( format( 'nullF8', ndims, dim ) ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index d7b4b8b..d351f56 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 170aae5cd3b6f977e3484b0cd16c75fc5c15980c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:46:33 +0000 Subject: [PATCH 04/26] Remove files --- index.d.ts | 92 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4939 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 d5d7768..0000000 --- a/index.d.ts +++ /dev/null @@ -1,92 +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; - - /** - * Boolean indicating whether returned views should include the selected dimension as a singleton dimension (default: false). - * - * ## Notes - * - * - Including the selected dimension as a singleton dimension can be useful when wanting to ensure that returned views remain broadcast compatible with the input ndarray. - */ - keepdim?: boolean; -} - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param x - input value -* @param dim - dimension index -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @param options.keepdim - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x: typedndarray, dim: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSelectDimension; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 25070e6..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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.2-esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=m(null,w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),l&&e(k,l,(function(){return b(c,u,x)})),k}export{b as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index b9076f9..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 isInteger } from '@stdlib/assert-is-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 filled from '@stdlib/array-base-filled';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = filled( null, ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","filled","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;uiDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAQ,KAAM1B,GAIpB2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 55072d5..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 23e02db89ad0ab6e061904bada57afb080c313e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:46:53 +0000 Subject: [PATCH 05/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 | 48 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - 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 | 224 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1093 ----- 43 files changed, 4875 insertions(+), 5117 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 30d62ba..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:18:23.308Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 342315d..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/select-dimension) 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 7a01fd4..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/select-dimension) 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 6963002..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 12 * * 2' - - # 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 + + ```
@@ -245,7 +236,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]. @@ -310,11 +301,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/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 d8e7344..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 nditerSelectDimension = 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 = nditerSelectDimension( x, 0 ); - 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 = nditerSelectDimension( x, 0 ); - - 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 9c014b1..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/select-dimension" -%% click B href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/select-dimension -[production-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/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 9c9336c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSelectDimension from '../docs/types/index'; -export = nditerSelectDimension; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 27e9aba..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var O=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var c=O(function(B,b){"use strict";var f=require("@stdlib/utils-define-nonenumerable-read-only-property"),S=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-is-boolean").isPrimitive,T=require("@stdlib/assert-is-integer").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),V=require("@stdlib/ndarray-base-assert-is-read-only"),g=require("@stdlib/assert-has-own-property"),y=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-filled"),R=require("@stdlib/ndarray-shape"),j=require("@stdlib/ndarray-base-normalize-index"),D=require("@stdlib/ndarray-base-numel"),F=require("@stdlib/ndarray-base-slice"),I=require("@stdlib/slice-ctor"),L=require("@stdlib/slice-base-args2multislice"),a=require("@stdlib/string-format");function q(i,r){var e,s,l,n,o,p,d,v,u,t;if(!P(i))throw new TypeError(a("invalid argument. First argument must be an ndarray. Value: `%s`.",i));if(!T(r))throw new TypeError(a("invalid argument. Second argument must be an integer. Value: `%s`.",r));if(n={writable:!1,keepdim:!1},arguments.length>2){if(e=arguments[2],!S(e))throw new TypeError(a("invalid argument. Options argument must be an object. Value: `%s`.",e));if(g(e,"readonly")){if(!w(e.readonly))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",e.readonly));if(n.writable=!e.readonly,n.writable&&V(i))throw new Error(a("invalid option. Cannot write to read-only array."))}if(g(e,"keepdim")){if(!w(e.keepdim))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","keepdim",e.keepdim));n.keepdim=e.keepdim}}if(s=R(i),l=s.length,u=j(r,l-1),u===-1)throw new RangeError(a("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",l,r));return v=D(s),v===0&&(p=!0),v=s[u],t=-1,d=x(null,l),o={},f(o,"next",h),f(o,"return",k),y&&f(o,y,E),o;function h(){var m;return t+=1,p||t>=v?{done:!0}:(n.keepdim?d[u]=new I(t,t+1,1):d[u]=t,m=L(d),{value:F(i,m,!0,n.writable),done:!1})}function k(m){return p=!0,arguments.length?{value:m,done:!0}:{done:!0}}function E(){return q(i,r,n)}}b.exports=q});var N=c();module.exports=N; -/** -* @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. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index cd682a1..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 isInteger = require( '@stdlib/assert-is-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 filled = require( '@stdlib/array-base-filled' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndslice = require( '@stdlib/ndarray-base-slice' );\nvar Slice = require( '@stdlib/slice-ctor' );\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\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 ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = filled( null, ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSelectDimension;\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 view along a specified dimension.\n*\n* @module @stdlib/ndarray-iter-select-dimension\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSelectDimension( x, 0 );\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,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAS,QAAS,2BAA4B,EAC9CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAU,QAAS,4BAA6B,EAChDC,EAAQ,QAAS,oBAAqB,EACtCC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA4C9C,SAASC,EAAuBC,EAAGC,EAAM,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACd,EAAWe,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAI,CAAE,EAM1G,GAJAI,EAAO,CACN,SAAY,GACZ,QAAW,EACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKb,EAAYa,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYjB,EAAYY,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACA,GAAKT,EAAYa,EAAS,SAAU,EAAI,CACvC,GAAK,CAACjB,EAAWiB,EAAQ,OAAQ,EAChC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAQ,OAAQ,CAAE,EAE3HG,EAAK,QAAUH,EAAQ,OACxB,CACD,CAOA,GALAC,EAAQX,EAAUQ,CAAE,EACpBI,EAAQD,EAAM,OAGdO,EAAIjB,EAAgBQ,EAAKG,EAAM,CAAE,EAC5BM,IAAM,GACV,MAAM,IAAI,WAAYZ,EAAQ,6GAA8GM,EAAOH,CAAI,CAAE,EAG1J,OAAAQ,EAAIf,EAAOS,CAAM,EACZM,IAAM,IACVF,EAAM,IAGPE,EAAIN,EAAOO,CAAE,EAGbC,EAAI,GAGJH,EAAMjB,EAAQ,KAAMa,CAAM,EAG1BE,EAAO,CAAC,EACRvB,EAAauB,EAAM,OAAQM,CAAK,EAChC7B,EAAauB,EAAM,SAAUO,CAAI,EAG5BvB,GACJP,EAAauB,EAAMhB,EAAgBwB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CACf,IAAIG,EAGJ,OADAJ,GAAK,EACAJ,GAAOI,GAAKF,EACT,CACN,KAAQ,EACT,GAGIJ,EAAK,QACTG,EAAKE,CAAE,EAAI,IAAId,EAAOe,EAAGA,EAAE,EAAG,CAAE,EAEhCH,EAAKE,CAAE,EAAIC,EAGZI,EAAIlB,EAAiBW,CAAI,EAGlB,CACN,MAASb,EAASK,EAAGe,EAAG,GAAMV,EAAK,QAAS,EAC5C,KAAQ,EACT,EACD,CASA,SAASQ,EAAKG,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOf,EAAuBC,EAAGC,EAAKI,CAAK,CAC5C,CACD,CAKAvB,EAAO,QAAUiB,IC3KjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "filled", "getShape", "normalizeIndex", "numel", "ndslice", "Slice", "args2multislice", "format", "nditerSelectDimension", "x", "dim", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "N", "d", "i", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 33d2556..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, dim[, options] ) - Returns an iterator which iterates over each view along a specified - dimension. - - 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. - - dim: integer - Dimension index. If less than zero, the index is resolved relative to - the last dimension, with the last dimension corresponding to the value - `-1`. - - 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. - - options.keepdim: boolean (optional) - Boolean indicating whether returned views should include the selected - dimension as a singleton dimension. Including the selected dimension as - a singleton dimension can be useful when wanting to ensure that returned - views remain broadcast compatible with the input ndarray. Default: - false. - - 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, 0 ); - > 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 ecb7b9d..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 nditerSelectDimension = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); // $ExpectType Iterator> - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSelectDimension( 123, 0 ); // $ExpectError - nditerSelectDimension( true, 0 ); // $ExpectError - nditerSelectDimension( false, 0 ); // $ExpectError - nditerSelectDimension( null, 0 ); // $ExpectError - nditerSelectDimension( undefined, 0 ); // $ExpectError - nditerSelectDimension( {}, 0 ); // $ExpectError - nditerSelectDimension( [], 0 ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0 ); // $ExpectError - - nditerSelectDimension( 123, 0, {} ); // $ExpectError - nditerSelectDimension( true, 0, {} ); // $ExpectError - nditerSelectDimension( false, 0, {} ); // $ExpectError - nditerSelectDimension( null, 0, {} ); // $ExpectError - nditerSelectDimension( undefined, 0, {} ); // $ExpectError - nditerSelectDimension( {}, 0, {} ); // $ExpectError - nditerSelectDimension( [], 0, {} ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSelectDimension( 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... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 'abc' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 123 ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 'abc' } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 123 } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': null } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': [] } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': {} } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSelectDimension(); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 872011c..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 nditerSelectDimension = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSelectDimension( x, 0 ); - -// 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 5acbfd8..d5d7768 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..25070e6 --- /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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.2-esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=m(null,w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),l&&e(k,l,(function(){return b(c,u,x)})),k}export{b as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b9076f9 --- /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 isInteger } from '@stdlib/assert-is-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 filled from '@stdlib/array-base-filled';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = filled( null, ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","filled","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;uiDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAQ,KAAM1B,GAIpB2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 766d309..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 view along a specified dimension. -* -* @module @stdlib/ndarray-iter-select-dimension -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSelectDimension( x, 0 ); -* -* 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 3c8710f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +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 isInteger = require( '@stdlib/assert-is-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 filled = require( '@stdlib/array-base-filled' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndslice = require( '@stdlib/ndarray-base-slice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param {ndarray} x - input value -* @param {integer} dim - dimension index -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} second argument must be an integer -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x, dim ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var N; - var d; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isInteger( dim ) ) { - throw new TypeError( format( 'null7f', dim ) ); - } - opts = { - 'writable': false, - 'keepdim': 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' ) ); - } - } - if ( hasOwnProp( options, 'keepdim' ) ) { - if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); - } - opts.keepdim = options.keepdim; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Normalize the dimension index: - d = normalizeIndex( dim, ndims-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'nullF8', ndims, dim ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of views (i.e., the dimension size): - N = shape[ d ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = filled( null, ndims ); - - // 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; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Update the index array to generate the next view: - if ( opts.keepdim ) { - idx[ d ] = new Slice( i, i+1, 1 ); - } else { - idx[ d ] = i; - } - // Create a multi-slice for the next view: - s = args2multislice( idx ); - - // Return the next slice: - return { - 'value': ndslice( 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 nditerSelectDimension( x, dim, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSelectDimension; diff --git a/package.json b/package.json index d351f56..a15ba47 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each view along a specified dimension.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-filled": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-normalize-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/slice-ctor": "^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..55072d5 --- /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 58efa84..0000000 --- a/test/test.js +++ /dev/null @@ -1,1093 +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 Slice = require( '@stdlib/slice-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSelectDimension = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSelectDimension, '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() { - nditerSelectDimension( value, 0 ); - }; - } -}); - -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() { - nditerSelectDimension( value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds (options)', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `keepdim` 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'keepdim': 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 - }); - nditerSelectDimension( x, 0, { - 'readonly': false - }); - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=default)', 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 = nditerSelectDimension( x, 0 ); - 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=3, dim=0, keepdim=false)', 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 = nditerSelectDimension( x, 0, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=true)', 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, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 0, { - 'keepdim': true - }); - 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=3, dim=1, keepdim=default)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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=3, dim=1, keepdim=false)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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=3, dim=2, keepdim=default)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( 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=3, dim=2, keepdim=false)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=2, keepdim=true)', 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, null, null, new Slice( 0, 1 ) ), - 'done': false - }, - { - 'value': slice( x, null, null, new Slice( 1, 2 ) ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': true - }); - 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, dim=1, keepdim=default)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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, dim=1, keepdim=false)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), 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, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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, dim=1)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - '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 = nditerSelectDimension( x, 0 ); - 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' ); - } - - it = nditerSelectDimension( x, 1 ); - 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' ); - } - - it = nditerSelectDimension( 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 nditerSelectDimension; - var it1; - var it2; - var x; - var i; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSelectDimension( x, 0 ); - 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 nditerSelectDimension; - var it; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From ca7a379cf725d70387a4bba9ba44f8c3199963a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 22 Sep 2024 08:06:41 +0000 Subject: [PATCH 06/26] Transform error messages --- lib/main.js | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 04145c7..f298502 100644 --- a/lib/main.js +++ b/lib/main.js @@ -35,7 +35,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var ndslice = require( '@stdlib/ndarray-base-slice' ); var Slice = require( '@stdlib/slice-ctor' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,10 +92,10 @@ function nditerSelectDimension( x, dim ) { 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 ( !isInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + throw new TypeError( format( 'null7f', dim ) ); } opts = { 'writable': false, @@ -104,20 +104,20 @@ function nditerSelectDimension( x, dim ) { 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' ) ); } } if ( hasOwnProp( options, 'keepdim' ) ) { if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) ); + throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); } opts.keepdim = options.keepdim; } @@ -129,7 +129,7 @@ function nditerSelectDimension( x, dim ) { // Normalize the dimension index: d = normalizeIndex( dim, ndims-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) ); + throw new RangeError( format( 'nullF8', ndims, dim ) ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index 5cfb4ac..9f2ec33 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 c521a0e5ebdeb6cc031cbba1d3f81f72642cf2d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 22 Sep 2024 08:08:55 +0000 Subject: [PATCH 07/26] Remove files --- index.d.ts | 92 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4939 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 d5d7768..0000000 --- a/index.d.ts +++ /dev/null @@ -1,92 +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; - - /** - * Boolean indicating whether returned views should include the selected dimension as a singleton dimension (default: false). - * - * ## Notes - * - * - Including the selected dimension as a singleton dimension can be useful when wanting to ensure that returned views remain broadcast compatible with the input ndarray. - */ - keepdim?: boolean; -} - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param x - input value -* @param dim - dimension index -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @param options.keepdim - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x: typedndarray, dim: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSelectDimension; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 25070e6..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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled@v0.2.2-esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=m(null,w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),l&&e(k,l,(function(){return b(c,u,x)})),k}export{b as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index b9076f9..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 isInteger } from '@stdlib/assert-is-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 filled from '@stdlib/array-base-filled';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = filled( null, ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","filled","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;uiDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAQ,KAAM1B,GAIpB2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 55072d5..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e3d5e7dafc91e4d4c4cbdb7f30792cfaeb80e1a2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 22 Sep 2024 08:09:12 +0000 Subject: [PATCH 08/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 | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - 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 | 224 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1093 ----- 42 files changed, 4875 insertions(+), 5117 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 342315d..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/select-dimension) 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 7a01fd4..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/select-dimension) 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 6963002..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 12 * * 2' - - # 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 + + ```
@@ -245,7 +236,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]. @@ -310,11 +301,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/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 d8e7344..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 nditerSelectDimension = 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 = nditerSelectDimension( x, 0 ); - 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 = nditerSelectDimension( x, 0 ); - - 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 9c014b1..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/select-dimension" -%% click B href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/select-dimension -[production-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/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 9c9336c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSelectDimension from '../docs/types/index'; -export = nditerSelectDimension; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c8c28a6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var O=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var c=O(function(B,b){"use strict";var f=require("@stdlib/utils-define-nonenumerable-read-only-property"),S=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-is-boolean").isPrimitive,T=require("@stdlib/assert-is-integer").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),V=require("@stdlib/ndarray-base-assert-is-read-only"),g=require("@stdlib/assert-has-own-property"),y=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-nulls"),R=require("@stdlib/ndarray-shape"),j=require("@stdlib/ndarray-base-normalize-index"),D=require("@stdlib/ndarray-base-numel"),F=require("@stdlib/ndarray-base-slice"),I=require("@stdlib/slice-ctor"),L=require("@stdlib/slice-base-args2multislice"),a=require("@stdlib/string-format");function q(i,r){var e,s,l,n,o,p,d,v,u,t;if(!P(i))throw new TypeError(a("invalid argument. First argument must be an ndarray. Value: `%s`.",i));if(!T(r))throw new TypeError(a("invalid argument. Second argument must be an integer. Value: `%s`.",r));if(n={writable:!1,keepdim:!1},arguments.length>2){if(e=arguments[2],!S(e))throw new TypeError(a("invalid argument. Options argument must be an object. Value: `%s`.",e));if(g(e,"readonly")){if(!w(e.readonly))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",e.readonly));if(n.writable=!e.readonly,n.writable&&V(i))throw new Error(a("invalid option. Cannot write to read-only array."))}if(g(e,"keepdim")){if(!w(e.keepdim))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","keepdim",e.keepdim));n.keepdim=e.keepdim}}if(s=R(i),l=s.length,u=j(r,l-1),u===-1)throw new RangeError(a("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",l,r));return v=D(s),v===0&&(p=!0),v=s[u],t=-1,d=x(l),o={},f(o,"next",h),f(o,"return",k),y&&f(o,y,E),o;function h(){var m;return t+=1,p||t>=v?{done:!0}:(n.keepdim?d[u]=new I(t,t+1,1):d[u]=t,m=L(d),{value:F(i,m,!0,n.writable),done:!1})}function k(m){return p=!0,arguments.length?{value:m,done:!0}:{done:!0}}function E(){return q(i,r,n)}}b.exports=q});var N=c();module.exports=N; -/** -* @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. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2254776..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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndslice = require( '@stdlib/ndarray-base-slice' );\nvar Slice = require( '@stdlib/slice-ctor' );\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\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 ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSelectDimension;\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 view along a specified dimension.\n*\n* @module @stdlib/ndarray-iter-select-dimension\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSelectDimension( x, 0 );\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,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAU,QAAS,4BAA6B,EAChDC,EAAQ,QAAS,oBAAqB,EACtCC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA4C9C,SAASC,EAAuBC,EAAGC,EAAM,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACd,EAAWe,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAI,CAAE,EAM1G,GAJAI,EAAO,CACN,SAAY,GACZ,QAAW,EACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKb,EAAYa,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYjB,EAAYY,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACA,GAAKT,EAAYa,EAAS,SAAU,EAAI,CACvC,GAAK,CAACjB,EAAWiB,EAAQ,OAAQ,EAChC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAQ,OAAQ,CAAE,EAE3HG,EAAK,QAAUH,EAAQ,OACxB,CACD,CAOA,GALAC,EAAQX,EAAUQ,CAAE,EACpBI,EAAQD,EAAM,OAGdO,EAAIjB,EAAgBQ,EAAKG,EAAM,CAAE,EAC5BM,IAAM,GACV,MAAM,IAAI,WAAYZ,EAAQ,6GAA8GM,EAAOH,CAAI,CAAE,EAG1J,OAAAQ,EAAIf,EAAOS,CAAM,EACZM,IAAM,IACVF,EAAM,IAGPE,EAAIN,EAAOO,CAAE,EAGbC,EAAI,GAGJH,EAAMjB,EAAOa,CAAM,EAGnBE,EAAO,CAAC,EACRvB,EAAauB,EAAM,OAAQM,CAAK,EAChC7B,EAAauB,EAAM,SAAUO,CAAI,EAG5BvB,GACJP,EAAauB,EAAMhB,EAAgBwB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CACf,IAAIG,EAGJ,OADAJ,GAAK,EACAJ,GAAOI,GAAKF,EACT,CACN,KAAQ,EACT,GAGIJ,EAAK,QACTG,EAAKE,CAAE,EAAI,IAAId,EAAOe,EAAGA,EAAE,EAAG,CAAE,EAEhCH,EAAKE,CAAE,EAAIC,EAGZI,EAAIlB,EAAiBW,CAAI,EAGlB,CACN,MAASb,EAASK,EAAGe,EAAG,GAAMV,EAAK,QAAS,EAC5C,KAAQ,EACT,EACD,CASA,SAASQ,EAAKG,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOf,EAAuBC,EAAGC,EAAKI,CAAK,CAC5C,CACD,CAKAvB,EAAO,QAAUiB,IC3KjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "nulls", "getShape", "normalizeIndex", "numel", "ndslice", "Slice", "args2multislice", "format", "nditerSelectDimension", "x", "dim", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "N", "d", "i", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 33d2556..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, dim[, options] ) - Returns an iterator which iterates over each view along a specified - dimension. - - 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. - - dim: integer - Dimension index. If less than zero, the index is resolved relative to - the last dimension, with the last dimension corresponding to the value - `-1`. - - 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. - - options.keepdim: boolean (optional) - Boolean indicating whether returned views should include the selected - dimension as a singleton dimension. Including the selected dimension as - a singleton dimension can be useful when wanting to ensure that returned - views remain broadcast compatible with the input ndarray. Default: - false. - - 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, 0 ); - > 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 ecb7b9d..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 nditerSelectDimension = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); // $ExpectType Iterator> - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSelectDimension( 123, 0 ); // $ExpectError - nditerSelectDimension( true, 0 ); // $ExpectError - nditerSelectDimension( false, 0 ); // $ExpectError - nditerSelectDimension( null, 0 ); // $ExpectError - nditerSelectDimension( undefined, 0 ); // $ExpectError - nditerSelectDimension( {}, 0 ); // $ExpectError - nditerSelectDimension( [], 0 ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0 ); // $ExpectError - - nditerSelectDimension( 123, 0, {} ); // $ExpectError - nditerSelectDimension( true, 0, {} ); // $ExpectError - nditerSelectDimension( false, 0, {} ); // $ExpectError - nditerSelectDimension( null, 0, {} ); // $ExpectError - nditerSelectDimension( undefined, 0, {} ); // $ExpectError - nditerSelectDimension( {}, 0, {} ); // $ExpectError - nditerSelectDimension( [], 0, {} ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSelectDimension( 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... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 'abc' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 123 ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 'abc' } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 123 } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': null } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': [] } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': {} } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSelectDimension(); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 872011c..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 nditerSelectDimension = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSelectDimension( x, 0 ); - -// 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 5acbfd8..d5d7768 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..c0d14ce --- /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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6897601 --- /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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 766d309..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 view along a specified dimension. -* -* @module @stdlib/ndarray-iter-select-dimension -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSelectDimension( x, 0 ); -* -* 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 f298502..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndslice = require( '@stdlib/ndarray-base-slice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param {ndarray} x - input value -* @param {integer} dim - dimension index -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} second argument must be an integer -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x, dim ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var N; - var d; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isInteger( dim ) ) { - throw new TypeError( format( 'null7f', dim ) ); - } - opts = { - 'writable': false, - 'keepdim': 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' ) ); - } - } - if ( hasOwnProp( options, 'keepdim' ) ) { - if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); - } - opts.keepdim = options.keepdim; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Normalize the dimension index: - d = normalizeIndex( dim, ndims-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'nullF8', ndims, dim ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of views (i.e., the dimension size): - N = shape[ d ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = nulls( ndims ); - - // 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; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Update the index array to generate the next view: - if ( opts.keepdim ) { - idx[ d ] = new Slice( i, i+1, 1 ); - } else { - idx[ d ] = i; - } - // Create a multi-slice for the next view: - s = args2multislice( idx ); - - // Return the next slice: - return { - 'value': ndslice( 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 nditerSelectDimension( x, dim, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSelectDimension; diff --git a/package.json b/package.json index 9f2ec33..a15ba47 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each view along a specified dimension.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-normalize-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/slice-ctor": "^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..1e359cd --- /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 58efa84..0000000 --- a/test/test.js +++ /dev/null @@ -1,1093 +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 Slice = require( '@stdlib/slice-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSelectDimension = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSelectDimension, '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() { - nditerSelectDimension( value, 0 ); - }; - } -}); - -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() { - nditerSelectDimension( value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds (options)', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `keepdim` 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'keepdim': 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 - }); - nditerSelectDimension( x, 0, { - 'readonly': false - }); - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=default)', 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 = nditerSelectDimension( x, 0 ); - 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=3, dim=0, keepdim=false)', 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 = nditerSelectDimension( x, 0, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=true)', 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, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 0, { - 'keepdim': true - }); - 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=3, dim=1, keepdim=default)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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=3, dim=1, keepdim=false)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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=3, dim=2, keepdim=default)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( 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=3, dim=2, keepdim=false)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=2, keepdim=true)', 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, null, null, new Slice( 0, 1 ) ), - 'done': false - }, - { - 'value': slice( x, null, null, new Slice( 1, 2 ) ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': true - }); - 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, dim=1, keepdim=default)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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, dim=1, keepdim=false)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), 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, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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, dim=1)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - '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 = nditerSelectDimension( x, 0 ); - 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' ); - } - - it = nditerSelectDimension( x, 1 ); - 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' ); - } - - it = nditerSelectDimension( 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 nditerSelectDimension; - var it1; - var it2; - var x; - var i; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSelectDimension( x, 0 ); - 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 nditerSelectDimension; - var it; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From c7ad2b4dc8d9dbd59bebcc72cabbbab67799d4f3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:39:53 +0000 Subject: [PATCH 09/26] Transform error messages --- lib/main.js | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 04145c7..f298502 100644 --- a/lib/main.js +++ b/lib/main.js @@ -35,7 +35,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var ndslice = require( '@stdlib/ndarray-base-slice' ); var Slice = require( '@stdlib/slice-ctor' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,10 +92,10 @@ function nditerSelectDimension( x, dim ) { 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 ( !isInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + throw new TypeError( format( 'null7f', dim ) ); } opts = { 'writable': false, @@ -104,20 +104,20 @@ function nditerSelectDimension( x, dim ) { 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' ) ); } } if ( hasOwnProp( options, 'keepdim' ) ) { if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) ); + throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); } opts.keepdim = options.keepdim; } @@ -129,7 +129,7 @@ function nditerSelectDimension( x, dim ) { // Normalize the dimension index: d = normalizeIndex( dim, ndims-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) ); + throw new RangeError( format( 'nullF8', ndims, dim ) ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index 5cfb4ac..9f2ec33 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 db85a67825985dfd9e807ac3e7dcfda082990221 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:21:49 +0000 Subject: [PATCH 10/26] Remove files --- index.d.ts | 92 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4939 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 d5d7768..0000000 --- a/index.d.ts +++ /dev/null @@ -1,92 +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; - - /** - * Boolean indicating whether returned views should include the selected dimension as a singleton dimension (default: false). - * - * ## Notes - * - * - Including the selected dimension as a singleton dimension can be useful when wanting to ensure that returned views remain broadcast compatible with the input ndarray. - */ - keepdim?: boolean; -} - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param x - input value -* @param dim - dimension index -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @param options.keepdim - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x: typedndarray, dim: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSelectDimension; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c0d14ce..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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6897601..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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1e359cd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1587764dd11f71ca08670d37adc69f76adb64ae4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:22:12 +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 | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - 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 | 224 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1093 ----- 43 files changed, 4875 insertions(+), 5118 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 8a0f32a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:30:33.601Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 342315d..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/select-dimension) 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 7a01fd4..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/select-dimension) 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 6963002..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 12 * * 2' - - # 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 + + ```
@@ -245,7 +236,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]. @@ -310,11 +301,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/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 d8e7344..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 nditerSelectDimension = 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 = nditerSelectDimension( x, 0 ); - 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 = nditerSelectDimension( x, 0 ); - - 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 9c014b1..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/select-dimension" -%% click B href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/select-dimension -[production-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/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 9c9336c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSelectDimension from '../docs/types/index'; -export = nditerSelectDimension; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c8c28a6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var O=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var c=O(function(B,b){"use strict";var f=require("@stdlib/utils-define-nonenumerable-read-only-property"),S=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-is-boolean").isPrimitive,T=require("@stdlib/assert-is-integer").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),V=require("@stdlib/ndarray-base-assert-is-read-only"),g=require("@stdlib/assert-has-own-property"),y=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-nulls"),R=require("@stdlib/ndarray-shape"),j=require("@stdlib/ndarray-base-normalize-index"),D=require("@stdlib/ndarray-base-numel"),F=require("@stdlib/ndarray-base-slice"),I=require("@stdlib/slice-ctor"),L=require("@stdlib/slice-base-args2multislice"),a=require("@stdlib/string-format");function q(i,r){var e,s,l,n,o,p,d,v,u,t;if(!P(i))throw new TypeError(a("invalid argument. First argument must be an ndarray. Value: `%s`.",i));if(!T(r))throw new TypeError(a("invalid argument. Second argument must be an integer. Value: `%s`.",r));if(n={writable:!1,keepdim:!1},arguments.length>2){if(e=arguments[2],!S(e))throw new TypeError(a("invalid argument. Options argument must be an object. Value: `%s`.",e));if(g(e,"readonly")){if(!w(e.readonly))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",e.readonly));if(n.writable=!e.readonly,n.writable&&V(i))throw new Error(a("invalid option. Cannot write to read-only array."))}if(g(e,"keepdim")){if(!w(e.keepdim))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","keepdim",e.keepdim));n.keepdim=e.keepdim}}if(s=R(i),l=s.length,u=j(r,l-1),u===-1)throw new RangeError(a("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",l,r));return v=D(s),v===0&&(p=!0),v=s[u],t=-1,d=x(l),o={},f(o,"next",h),f(o,"return",k),y&&f(o,y,E),o;function h(){var m;return t+=1,p||t>=v?{done:!0}:(n.keepdim?d[u]=new I(t,t+1,1):d[u]=t,m=L(d),{value:F(i,m,!0,n.writable),done:!1})}function k(m){return p=!0,arguments.length?{value:m,done:!0}:{done:!0}}function E(){return q(i,r,n)}}b.exports=q});var N=c();module.exports=N; -/** -* @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. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2254776..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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndslice = require( '@stdlib/ndarray-base-slice' );\nvar Slice = require( '@stdlib/slice-ctor' );\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\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 ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSelectDimension;\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 view along a specified dimension.\n*\n* @module @stdlib/ndarray-iter-select-dimension\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSelectDimension( x, 0 );\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,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAU,QAAS,4BAA6B,EAChDC,EAAQ,QAAS,oBAAqB,EACtCC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA4C9C,SAASC,EAAuBC,EAAGC,EAAM,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACd,EAAWe,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAI,CAAE,EAM1G,GAJAI,EAAO,CACN,SAAY,GACZ,QAAW,EACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKb,EAAYa,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYjB,EAAYY,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACA,GAAKT,EAAYa,EAAS,SAAU,EAAI,CACvC,GAAK,CAACjB,EAAWiB,EAAQ,OAAQ,EAChC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAQ,OAAQ,CAAE,EAE3HG,EAAK,QAAUH,EAAQ,OACxB,CACD,CAOA,GALAC,EAAQX,EAAUQ,CAAE,EACpBI,EAAQD,EAAM,OAGdO,EAAIjB,EAAgBQ,EAAKG,EAAM,CAAE,EAC5BM,IAAM,GACV,MAAM,IAAI,WAAYZ,EAAQ,6GAA8GM,EAAOH,CAAI,CAAE,EAG1J,OAAAQ,EAAIf,EAAOS,CAAM,EACZM,IAAM,IACVF,EAAM,IAGPE,EAAIN,EAAOO,CAAE,EAGbC,EAAI,GAGJH,EAAMjB,EAAOa,CAAM,EAGnBE,EAAO,CAAC,EACRvB,EAAauB,EAAM,OAAQM,CAAK,EAChC7B,EAAauB,EAAM,SAAUO,CAAI,EAG5BvB,GACJP,EAAauB,EAAMhB,EAAgBwB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CACf,IAAIG,EAGJ,OADAJ,GAAK,EACAJ,GAAOI,GAAKF,EACT,CACN,KAAQ,EACT,GAGIJ,EAAK,QACTG,EAAKE,CAAE,EAAI,IAAId,EAAOe,EAAGA,EAAE,EAAG,CAAE,EAEhCH,EAAKE,CAAE,EAAIC,EAGZI,EAAIlB,EAAiBW,CAAI,EAGlB,CACN,MAASb,EAASK,EAAGe,EAAG,GAAMV,EAAK,QAAS,EAC5C,KAAQ,EACT,EACD,CASA,SAASQ,EAAKG,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOf,EAAuBC,EAAGC,EAAKI,CAAK,CAC5C,CACD,CAKAvB,EAAO,QAAUiB,IC3KjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "nulls", "getShape", "normalizeIndex", "numel", "ndslice", "Slice", "args2multislice", "format", "nditerSelectDimension", "x", "dim", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "N", "d", "i", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 33d2556..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, dim[, options] ) - Returns an iterator which iterates over each view along a specified - dimension. - - 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. - - dim: integer - Dimension index. If less than zero, the index is resolved relative to - the last dimension, with the last dimension corresponding to the value - `-1`. - - 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. - - options.keepdim: boolean (optional) - Boolean indicating whether returned views should include the selected - dimension as a singleton dimension. Including the selected dimension as - a singleton dimension can be useful when wanting to ensure that returned - views remain broadcast compatible with the input ndarray. Default: - false. - - 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, 0 ); - > 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 ecb7b9d..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 nditerSelectDimension = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); // $ExpectType Iterator> - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSelectDimension( 123, 0 ); // $ExpectError - nditerSelectDimension( true, 0 ); // $ExpectError - nditerSelectDimension( false, 0 ); // $ExpectError - nditerSelectDimension( null, 0 ); // $ExpectError - nditerSelectDimension( undefined, 0 ); // $ExpectError - nditerSelectDimension( {}, 0 ); // $ExpectError - nditerSelectDimension( [], 0 ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0 ); // $ExpectError - - nditerSelectDimension( 123, 0, {} ); // $ExpectError - nditerSelectDimension( true, 0, {} ); // $ExpectError - nditerSelectDimension( false, 0, {} ); // $ExpectError - nditerSelectDimension( null, 0, {} ); // $ExpectError - nditerSelectDimension( undefined, 0, {} ); // $ExpectError - nditerSelectDimension( {}, 0, {} ); // $ExpectError - nditerSelectDimension( [], 0, {} ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSelectDimension( 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... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 'abc' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 123 ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 'abc' } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 123 } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': null } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': [] } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': {} } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSelectDimension(); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 872011c..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 nditerSelectDimension = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSelectDimension( x, 0 ); - -// 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 5acbfd8..d5d7768 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..c0d14ce --- /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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6897601 --- /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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 766d309..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 view along a specified dimension. -* -* @module @stdlib/ndarray-iter-select-dimension -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSelectDimension( x, 0 ); -* -* 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 f298502..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndslice = require( '@stdlib/ndarray-base-slice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param {ndarray} x - input value -* @param {integer} dim - dimension index -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} second argument must be an integer -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x, dim ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var N; - var d; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isInteger( dim ) ) { - throw new TypeError( format( 'null7f', dim ) ); - } - opts = { - 'writable': false, - 'keepdim': 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' ) ); - } - } - if ( hasOwnProp( options, 'keepdim' ) ) { - if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); - } - opts.keepdim = options.keepdim; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Normalize the dimension index: - d = normalizeIndex( dim, ndims-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'nullF8', ndims, dim ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of views (i.e., the dimension size): - N = shape[ d ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = nulls( ndims ); - - // 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; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Update the index array to generate the next view: - if ( opts.keepdim ) { - idx[ d ] = new Slice( i, i+1, 1 ); - } else { - idx[ d ] = i; - } - // Create a multi-slice for the next view: - s = args2multislice( idx ); - - // Return the next slice: - return { - 'value': ndslice( 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 nditerSelectDimension( x, dim, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSelectDimension; diff --git a/package.json b/package.json index 9f2ec33..a15ba47 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each view along a specified dimension.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-normalize-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/slice-ctor": "^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..1e359cd --- /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 58efa84..0000000 --- a/test/test.js +++ /dev/null @@ -1,1093 +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 Slice = require( '@stdlib/slice-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSelectDimension = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSelectDimension, '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() { - nditerSelectDimension( value, 0 ); - }; - } -}); - -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() { - nditerSelectDimension( value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds (options)', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `keepdim` 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'keepdim': 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 - }); - nditerSelectDimension( x, 0, { - 'readonly': false - }); - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=default)', 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 = nditerSelectDimension( x, 0 ); - 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=3, dim=0, keepdim=false)', 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 = nditerSelectDimension( x, 0, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=true)', 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, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 0, { - 'keepdim': true - }); - 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=3, dim=1, keepdim=default)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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=3, dim=1, keepdim=false)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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=3, dim=2, keepdim=default)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( 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=3, dim=2, keepdim=false)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=2, keepdim=true)', 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, null, null, new Slice( 0, 1 ) ), - 'done': false - }, - { - 'value': slice( x, null, null, new Slice( 1, 2 ) ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': true - }); - 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, dim=1, keepdim=default)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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, dim=1, keepdim=false)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), 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, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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, dim=1)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - '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 = nditerSelectDimension( x, 0 ); - 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' ); - } - - it = nditerSelectDimension( x, 1 ); - 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' ); - } - - it = nditerSelectDimension( 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 nditerSelectDimension; - var it1; - var it2; - var x; - var i; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSelectDimension( x, 0 ); - 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 nditerSelectDimension; - var it; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 23e5d427b05afd2e6dc8cce46cd9286dce7b9954 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:26:23 +0000 Subject: [PATCH 12/26] Transform error messages --- lib/main.js | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 04145c7..f298502 100644 --- a/lib/main.js +++ b/lib/main.js @@ -35,7 +35,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var ndslice = require( '@stdlib/ndarray-base-slice' ); var Slice = require( '@stdlib/slice-ctor' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,10 +92,10 @@ function nditerSelectDimension( x, dim ) { 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 ( !isInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + throw new TypeError( format( 'null7f', dim ) ); } opts = { 'writable': false, @@ -104,20 +104,20 @@ function nditerSelectDimension( x, dim ) { 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' ) ); } } if ( hasOwnProp( options, 'keepdim' ) ) { if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) ); + throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); } opts.keepdim = options.keepdim; } @@ -129,7 +129,7 @@ function nditerSelectDimension( x, dim ) { // Normalize the dimension index: d = normalizeIndex( dim, ndims-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) ); + throw new RangeError( format( 'nullF8', ndims, dim ) ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index 5cfb4ac..9f2ec33 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 249ca8fac22a2714d14ee898650ccfeabe91586d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:26:56 +0000 Subject: [PATCH 13/26] Remove files --- index.d.ts | 92 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4939 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 d5d7768..0000000 --- a/index.d.ts +++ /dev/null @@ -1,92 +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; - - /** - * Boolean indicating whether returned views should include the selected dimension as a singleton dimension (default: false). - * - * ## Notes - * - * - Including the selected dimension as a singleton dimension can be useful when wanting to ensure that returned views remain broadcast compatible with the input ndarray. - */ - keepdim?: boolean; -} - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param x - input value -* @param dim - dimension index -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @param options.keepdim - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x: typedndarray, dim: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSelectDimension; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c0d14ce..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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6897601..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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1e359cd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d852402be8e27793ce4a3eca7e2ee02c665838c8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:27:15 +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 | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - 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 | 224 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1093 ----- 43 files changed, 4875 insertions(+), 5118 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 c51ae94..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:33:43.549Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 342315d..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/select-dimension) 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 7a01fd4..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/select-dimension) 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 6963002..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 12 * * 2' - - # 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 + + ```
@@ -245,7 +236,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]. @@ -310,11 +301,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/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 d8e7344..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 nditerSelectDimension = 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 = nditerSelectDimension( x, 0 ); - 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 = nditerSelectDimension( x, 0 ); - - 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 9c014b1..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/select-dimension" -%% click B href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/select-dimension -[production-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/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 9c9336c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSelectDimension from '../docs/types/index'; -export = nditerSelectDimension; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c8c28a6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var O=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var c=O(function(B,b){"use strict";var f=require("@stdlib/utils-define-nonenumerable-read-only-property"),S=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-is-boolean").isPrimitive,T=require("@stdlib/assert-is-integer").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),V=require("@stdlib/ndarray-base-assert-is-read-only"),g=require("@stdlib/assert-has-own-property"),y=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-nulls"),R=require("@stdlib/ndarray-shape"),j=require("@stdlib/ndarray-base-normalize-index"),D=require("@stdlib/ndarray-base-numel"),F=require("@stdlib/ndarray-base-slice"),I=require("@stdlib/slice-ctor"),L=require("@stdlib/slice-base-args2multislice"),a=require("@stdlib/string-format");function q(i,r){var e,s,l,n,o,p,d,v,u,t;if(!P(i))throw new TypeError(a("invalid argument. First argument must be an ndarray. Value: `%s`.",i));if(!T(r))throw new TypeError(a("invalid argument. Second argument must be an integer. Value: `%s`.",r));if(n={writable:!1,keepdim:!1},arguments.length>2){if(e=arguments[2],!S(e))throw new TypeError(a("invalid argument. Options argument must be an object. Value: `%s`.",e));if(g(e,"readonly")){if(!w(e.readonly))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",e.readonly));if(n.writable=!e.readonly,n.writable&&V(i))throw new Error(a("invalid option. Cannot write to read-only array."))}if(g(e,"keepdim")){if(!w(e.keepdim))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","keepdim",e.keepdim));n.keepdim=e.keepdim}}if(s=R(i),l=s.length,u=j(r,l-1),u===-1)throw new RangeError(a("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",l,r));return v=D(s),v===0&&(p=!0),v=s[u],t=-1,d=x(l),o={},f(o,"next",h),f(o,"return",k),y&&f(o,y,E),o;function h(){var m;return t+=1,p||t>=v?{done:!0}:(n.keepdim?d[u]=new I(t,t+1,1):d[u]=t,m=L(d),{value:F(i,m,!0,n.writable),done:!1})}function k(m){return p=!0,arguments.length?{value:m,done:!0}:{done:!0}}function E(){return q(i,r,n)}}b.exports=q});var N=c();module.exports=N; -/** -* @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. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2254776..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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndslice = require( '@stdlib/ndarray-base-slice' );\nvar Slice = require( '@stdlib/slice-ctor' );\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\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 ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSelectDimension;\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 view along a specified dimension.\n*\n* @module @stdlib/ndarray-iter-select-dimension\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSelectDimension( x, 0 );\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,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAU,QAAS,4BAA6B,EAChDC,EAAQ,QAAS,oBAAqB,EACtCC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA4C9C,SAASC,EAAuBC,EAAGC,EAAM,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACd,EAAWe,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAI,CAAE,EAM1G,GAJAI,EAAO,CACN,SAAY,GACZ,QAAW,EACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKb,EAAYa,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYjB,EAAYY,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACA,GAAKT,EAAYa,EAAS,SAAU,EAAI,CACvC,GAAK,CAACjB,EAAWiB,EAAQ,OAAQ,EAChC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAQ,OAAQ,CAAE,EAE3HG,EAAK,QAAUH,EAAQ,OACxB,CACD,CAOA,GALAC,EAAQX,EAAUQ,CAAE,EACpBI,EAAQD,EAAM,OAGdO,EAAIjB,EAAgBQ,EAAKG,EAAM,CAAE,EAC5BM,IAAM,GACV,MAAM,IAAI,WAAYZ,EAAQ,6GAA8GM,EAAOH,CAAI,CAAE,EAG1J,OAAAQ,EAAIf,EAAOS,CAAM,EACZM,IAAM,IACVF,EAAM,IAGPE,EAAIN,EAAOO,CAAE,EAGbC,EAAI,GAGJH,EAAMjB,EAAOa,CAAM,EAGnBE,EAAO,CAAC,EACRvB,EAAauB,EAAM,OAAQM,CAAK,EAChC7B,EAAauB,EAAM,SAAUO,CAAI,EAG5BvB,GACJP,EAAauB,EAAMhB,EAAgBwB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CACf,IAAIG,EAGJ,OADAJ,GAAK,EACAJ,GAAOI,GAAKF,EACT,CACN,KAAQ,EACT,GAGIJ,EAAK,QACTG,EAAKE,CAAE,EAAI,IAAId,EAAOe,EAAGA,EAAE,EAAG,CAAE,EAEhCH,EAAKE,CAAE,EAAIC,EAGZI,EAAIlB,EAAiBW,CAAI,EAGlB,CACN,MAASb,EAASK,EAAGe,EAAG,GAAMV,EAAK,QAAS,EAC5C,KAAQ,EACT,EACD,CASA,SAASQ,EAAKG,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOf,EAAuBC,EAAGC,EAAKI,CAAK,CAC5C,CACD,CAKAvB,EAAO,QAAUiB,IC3KjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "nulls", "getShape", "normalizeIndex", "numel", "ndslice", "Slice", "args2multislice", "format", "nditerSelectDimension", "x", "dim", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "N", "d", "i", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 33d2556..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, dim[, options] ) - Returns an iterator which iterates over each view along a specified - dimension. - - 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. - - dim: integer - Dimension index. If less than zero, the index is resolved relative to - the last dimension, with the last dimension corresponding to the value - `-1`. - - 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. - - options.keepdim: boolean (optional) - Boolean indicating whether returned views should include the selected - dimension as a singleton dimension. Including the selected dimension as - a singleton dimension can be useful when wanting to ensure that returned - views remain broadcast compatible with the input ndarray. Default: - false. - - 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, 0 ); - > 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 ecb7b9d..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 nditerSelectDimension = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); // $ExpectType Iterator> - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSelectDimension( 123, 0 ); // $ExpectError - nditerSelectDimension( true, 0 ); // $ExpectError - nditerSelectDimension( false, 0 ); // $ExpectError - nditerSelectDimension( null, 0 ); // $ExpectError - nditerSelectDimension( undefined, 0 ); // $ExpectError - nditerSelectDimension( {}, 0 ); // $ExpectError - nditerSelectDimension( [], 0 ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0 ); // $ExpectError - - nditerSelectDimension( 123, 0, {} ); // $ExpectError - nditerSelectDimension( true, 0, {} ); // $ExpectError - nditerSelectDimension( false, 0, {} ); // $ExpectError - nditerSelectDimension( null, 0, {} ); // $ExpectError - nditerSelectDimension( undefined, 0, {} ); // $ExpectError - nditerSelectDimension( {}, 0, {} ); // $ExpectError - nditerSelectDimension( [], 0, {} ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSelectDimension( 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... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 'abc' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 123 ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 'abc' } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 123 } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': null } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': [] } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': {} } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSelectDimension(); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 872011c..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 nditerSelectDimension = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSelectDimension( x, 0 ); - -// 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 5acbfd8..d5d7768 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..c0d14ce --- /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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6897601 --- /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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 766d309..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 view along a specified dimension. -* -* @module @stdlib/ndarray-iter-select-dimension -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSelectDimension( x, 0 ); -* -* 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 f298502..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndslice = require( '@stdlib/ndarray-base-slice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param {ndarray} x - input value -* @param {integer} dim - dimension index -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} second argument must be an integer -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x, dim ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var N; - var d; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isInteger( dim ) ) { - throw new TypeError( format( 'null7f', dim ) ); - } - opts = { - 'writable': false, - 'keepdim': 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' ) ); - } - } - if ( hasOwnProp( options, 'keepdim' ) ) { - if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); - } - opts.keepdim = options.keepdim; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Normalize the dimension index: - d = normalizeIndex( dim, ndims-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'nullF8', ndims, dim ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of views (i.e., the dimension size): - N = shape[ d ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = nulls( ndims ); - - // 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; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Update the index array to generate the next view: - if ( opts.keepdim ) { - idx[ d ] = new Slice( i, i+1, 1 ); - } else { - idx[ d ] = i; - } - // Create a multi-slice for the next view: - s = args2multislice( idx ); - - // Return the next slice: - return { - 'value': ndslice( 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 nditerSelectDimension( x, dim, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSelectDimension; diff --git a/package.json b/package.json index 9f2ec33..a15ba47 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each view along a specified dimension.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-normalize-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/slice-ctor": "^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..1e359cd --- /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 58efa84..0000000 --- a/test/test.js +++ /dev/null @@ -1,1093 +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 Slice = require( '@stdlib/slice-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSelectDimension = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSelectDimension, '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() { - nditerSelectDimension( value, 0 ); - }; - } -}); - -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() { - nditerSelectDimension( value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds (options)', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `keepdim` 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'keepdim': 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 - }); - nditerSelectDimension( x, 0, { - 'readonly': false - }); - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=default)', 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 = nditerSelectDimension( x, 0 ); - 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=3, dim=0, keepdim=false)', 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 = nditerSelectDimension( x, 0, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=true)', 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, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 0, { - 'keepdim': true - }); - 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=3, dim=1, keepdim=default)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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=3, dim=1, keepdim=false)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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=3, dim=2, keepdim=default)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( 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=3, dim=2, keepdim=false)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=2, keepdim=true)', 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, null, null, new Slice( 0, 1 ) ), - 'done': false - }, - { - 'value': slice( x, null, null, new Slice( 1, 2 ) ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': true - }); - 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, dim=1, keepdim=default)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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, dim=1, keepdim=false)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), 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, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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, dim=1)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - '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 = nditerSelectDimension( x, 0 ); - 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' ); - } - - it = nditerSelectDimension( x, 1 ); - 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' ); - } - - it = nditerSelectDimension( 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 nditerSelectDimension; - var it1; - var it2; - var x; - var i; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSelectDimension( x, 0 ); - 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 nditerSelectDimension; - var it; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 1deba1e2017ed0c573c0472f0ac436a179c3fa4e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:43:06 +0000 Subject: [PATCH 15/26] Transform error messages --- lib/main.js | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 04145c7..f298502 100644 --- a/lib/main.js +++ b/lib/main.js @@ -35,7 +35,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var ndslice = require( '@stdlib/ndarray-base-slice' ); var Slice = require( '@stdlib/slice-ctor' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,10 +92,10 @@ function nditerSelectDimension( x, dim ) { 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 ( !isInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + throw new TypeError( format( 'null7f', dim ) ); } opts = { 'writable': false, @@ -104,20 +104,20 @@ function nditerSelectDimension( x, dim ) { 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' ) ); } } if ( hasOwnProp( options, 'keepdim' ) ) { if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) ); + throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); } opts.keepdim = options.keepdim; } @@ -129,7 +129,7 @@ function nditerSelectDimension( x, dim ) { // Normalize the dimension index: d = normalizeIndex( dim, ndims-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) ); + throw new RangeError( format( 'nullF8', ndims, dim ) ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index ec80183..1b98bb3 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 87aa5862576659ebf7543fd9fde4d4af54c625f9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:47:40 +0000 Subject: [PATCH 16/26] Remove files --- index.d.ts | 92 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4939 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 d5d7768..0000000 --- a/index.d.ts +++ /dev/null @@ -1,92 +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; - - /** - * Boolean indicating whether returned views should include the selected dimension as a singleton dimension (default: false). - * - * ## Notes - * - * - Including the selected dimension as a singleton dimension can be useful when wanting to ensure that returned views remain broadcast compatible with the input ndarray. - */ - keepdim?: boolean; -} - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param x - input value -* @param dim - dimension index -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @param options.keepdim - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x: typedndarray, dim: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSelectDimension; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c0d14ce..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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6897601..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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1e359cd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e6db81d55032e9629e3464466aa8a47b6120dd31 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:47:56 +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 | 59 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - 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 | 224 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1093 ---- 44 files changed, 4875 insertions(+), 5223 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 39d5e29..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T06:43:30.769Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 342315d..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/select-dimension) 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 7a01fd4..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/select-dimension) 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 6963002..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 12 * * 2' - - # 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 + + ```
@@ -245,7 +236,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]. @@ -310,11 +301,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/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 d8e7344..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 nditerSelectDimension = 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 = nditerSelectDimension( x, 0 ); - 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 = nditerSelectDimension( x, 0 ); - - 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 9c014b1..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/select-dimension" -%% click B href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/select-dimension -[production-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/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 9c9336c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSelectDimension from '../docs/types/index'; -export = nditerSelectDimension; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c8c28a6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var O=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var c=O(function(B,b){"use strict";var f=require("@stdlib/utils-define-nonenumerable-read-only-property"),S=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-is-boolean").isPrimitive,T=require("@stdlib/assert-is-integer").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),V=require("@stdlib/ndarray-base-assert-is-read-only"),g=require("@stdlib/assert-has-own-property"),y=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-nulls"),R=require("@stdlib/ndarray-shape"),j=require("@stdlib/ndarray-base-normalize-index"),D=require("@stdlib/ndarray-base-numel"),F=require("@stdlib/ndarray-base-slice"),I=require("@stdlib/slice-ctor"),L=require("@stdlib/slice-base-args2multislice"),a=require("@stdlib/string-format");function q(i,r){var e,s,l,n,o,p,d,v,u,t;if(!P(i))throw new TypeError(a("invalid argument. First argument must be an ndarray. Value: `%s`.",i));if(!T(r))throw new TypeError(a("invalid argument. Second argument must be an integer. Value: `%s`.",r));if(n={writable:!1,keepdim:!1},arguments.length>2){if(e=arguments[2],!S(e))throw new TypeError(a("invalid argument. Options argument must be an object. Value: `%s`.",e));if(g(e,"readonly")){if(!w(e.readonly))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",e.readonly));if(n.writable=!e.readonly,n.writable&&V(i))throw new Error(a("invalid option. Cannot write to read-only array."))}if(g(e,"keepdim")){if(!w(e.keepdim))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","keepdim",e.keepdim));n.keepdim=e.keepdim}}if(s=R(i),l=s.length,u=j(r,l-1),u===-1)throw new RangeError(a("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",l,r));return v=D(s),v===0&&(p=!0),v=s[u],t=-1,d=x(l),o={},f(o,"next",h),f(o,"return",k),y&&f(o,y,E),o;function h(){var m;return t+=1,p||t>=v?{done:!0}:(n.keepdim?d[u]=new I(t,t+1,1):d[u]=t,m=L(d),{value:F(i,m,!0,n.writable),done:!1})}function k(m){return p=!0,arguments.length?{value:m,done:!0}:{done:!0}}function E(){return q(i,r,n)}}b.exports=q});var N=c();module.exports=N; -/** -* @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. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2254776..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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndslice = require( '@stdlib/ndarray-base-slice' );\nvar Slice = require( '@stdlib/slice-ctor' );\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\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 ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSelectDimension;\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 view along a specified dimension.\n*\n* @module @stdlib/ndarray-iter-select-dimension\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSelectDimension( x, 0 );\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,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAU,QAAS,4BAA6B,EAChDC,EAAQ,QAAS,oBAAqB,EACtCC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA4C9C,SAASC,EAAuBC,EAAGC,EAAM,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACd,EAAWe,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAI,CAAE,EAM1G,GAJAI,EAAO,CACN,SAAY,GACZ,QAAW,EACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKb,EAAYa,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYjB,EAAYY,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACA,GAAKT,EAAYa,EAAS,SAAU,EAAI,CACvC,GAAK,CAACjB,EAAWiB,EAAQ,OAAQ,EAChC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAQ,OAAQ,CAAE,EAE3HG,EAAK,QAAUH,EAAQ,OACxB,CACD,CAOA,GALAC,EAAQX,EAAUQ,CAAE,EACpBI,EAAQD,EAAM,OAGdO,EAAIjB,EAAgBQ,EAAKG,EAAM,CAAE,EAC5BM,IAAM,GACV,MAAM,IAAI,WAAYZ,EAAQ,6GAA8GM,EAAOH,CAAI,CAAE,EAG1J,OAAAQ,EAAIf,EAAOS,CAAM,EACZM,IAAM,IACVF,EAAM,IAGPE,EAAIN,EAAOO,CAAE,EAGbC,EAAI,GAGJH,EAAMjB,EAAOa,CAAM,EAGnBE,EAAO,CAAC,EACRvB,EAAauB,EAAM,OAAQM,CAAK,EAChC7B,EAAauB,EAAM,SAAUO,CAAI,EAG5BvB,GACJP,EAAauB,EAAMhB,EAAgBwB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CACf,IAAIG,EAGJ,OADAJ,GAAK,EACAJ,GAAOI,GAAKF,EACT,CACN,KAAQ,EACT,GAGIJ,EAAK,QACTG,EAAKE,CAAE,EAAI,IAAId,EAAOe,EAAGA,EAAE,EAAG,CAAE,EAEhCH,EAAKE,CAAE,EAAIC,EAGZI,EAAIlB,EAAiBW,CAAI,EAGlB,CACN,MAASb,EAASK,EAAGe,EAAG,GAAMV,EAAK,QAAS,EAC5C,KAAQ,EACT,EACD,CASA,SAASQ,EAAKG,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOf,EAAuBC,EAAGC,EAAKI,CAAK,CAC5C,CACD,CAKAvB,EAAO,QAAUiB,IC3KjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "nulls", "getShape", "normalizeIndex", "numel", "ndslice", "Slice", "args2multislice", "format", "nditerSelectDimension", "x", "dim", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "N", "d", "i", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 33d2556..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, dim[, options] ) - Returns an iterator which iterates over each view along a specified - dimension. - - 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. - - dim: integer - Dimension index. If less than zero, the index is resolved relative to - the last dimension, with the last dimension corresponding to the value - `-1`. - - 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. - - options.keepdim: boolean (optional) - Boolean indicating whether returned views should include the selected - dimension as a singleton dimension. Including the selected dimension as - a singleton dimension can be useful when wanting to ensure that returned - views remain broadcast compatible with the input ndarray. Default: - false. - - 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, 0 ); - > 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 ecb7b9d..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 nditerSelectDimension = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); // $ExpectType Iterator> - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSelectDimension( 123, 0 ); // $ExpectError - nditerSelectDimension( true, 0 ); // $ExpectError - nditerSelectDimension( false, 0 ); // $ExpectError - nditerSelectDimension( null, 0 ); // $ExpectError - nditerSelectDimension( undefined, 0 ); // $ExpectError - nditerSelectDimension( {}, 0 ); // $ExpectError - nditerSelectDimension( [], 0 ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0 ); // $ExpectError - - nditerSelectDimension( 123, 0, {} ); // $ExpectError - nditerSelectDimension( true, 0, {} ); // $ExpectError - nditerSelectDimension( false, 0, {} ); // $ExpectError - nditerSelectDimension( null, 0, {} ); // $ExpectError - nditerSelectDimension( undefined, 0, {} ); // $ExpectError - nditerSelectDimension( {}, 0, {} ); // $ExpectError - nditerSelectDimension( [], 0, {} ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSelectDimension( 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... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 'abc' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 123 ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 'abc' } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 123 } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': null } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': [] } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': {} } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSelectDimension(); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 872011c..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 nditerSelectDimension = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSelectDimension( x, 0 ); - -// 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 5acbfd8..d5d7768 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..c0d14ce --- /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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6897601 --- /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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 766d309..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 view along a specified dimension. -* -* @module @stdlib/ndarray-iter-select-dimension -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSelectDimension( x, 0 ); -* -* 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 f298502..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndslice = require( '@stdlib/ndarray-base-slice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param {ndarray} x - input value -* @param {integer} dim - dimension index -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} second argument must be an integer -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x, dim ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var N; - var d; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isInteger( dim ) ) { - throw new TypeError( format( 'null7f', dim ) ); - } - opts = { - 'writable': false, - 'keepdim': 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' ) ); - } - } - if ( hasOwnProp( options, 'keepdim' ) ) { - if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); - } - opts.keepdim = options.keepdim; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Normalize the dimension index: - d = normalizeIndex( dim, ndims-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'nullF8', ndims, dim ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of views (i.e., the dimension size): - N = shape[ d ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = nulls( ndims ); - - // 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; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Update the index array to generate the next view: - if ( opts.keepdim ) { - idx[ d ] = new Slice( i, i+1, 1 ); - } else { - idx[ d ] = i; - } - // Create a multi-slice for the next view: - s = args2multislice( idx ); - - // Return the next slice: - return { - 'value': ndslice( 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 nditerSelectDimension( x, dim, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSelectDimension; diff --git a/package.json b/package.json index 1b98bb3..a15ba47 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each view along a specified dimension.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-normalize-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/slice-ctor": "^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..1e359cd --- /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 58efa84..0000000 --- a/test/test.js +++ /dev/null @@ -1,1093 +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 Slice = require( '@stdlib/slice-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSelectDimension = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSelectDimension, '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() { - nditerSelectDimension( value, 0 ); - }; - } -}); - -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() { - nditerSelectDimension( value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds (options)', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `keepdim` 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'keepdim': 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 - }); - nditerSelectDimension( x, 0, { - 'readonly': false - }); - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=default)', 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 = nditerSelectDimension( x, 0 ); - 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=3, dim=0, keepdim=false)', 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 = nditerSelectDimension( x, 0, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=true)', 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, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 0, { - 'keepdim': true - }); - 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=3, dim=1, keepdim=default)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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=3, dim=1, keepdim=false)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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=3, dim=2, keepdim=default)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( 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=3, dim=2, keepdim=false)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=2, keepdim=true)', 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, null, null, new Slice( 0, 1 ) ), - 'done': false - }, - { - 'value': slice( x, null, null, new Slice( 1, 2 ) ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': true - }); - 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, dim=1, keepdim=default)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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, dim=1, keepdim=false)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), 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, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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, dim=1)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - '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 = nditerSelectDimension( x, 0 ); - 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' ); - } - - it = nditerSelectDimension( x, 1 ); - 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' ); - } - - it = nditerSelectDimension( 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 nditerSelectDimension; - var it1; - var it2; - var x; - var i; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSelectDimension( x, 0 ); - 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 nditerSelectDimension; - var it; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 40ca85ea0b73f20005125b2a764bede626118db7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 03:17:22 +0000 Subject: [PATCH 18/26] Transform error messages --- lib/main.js | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 04145c7..f298502 100644 --- a/lib/main.js +++ b/lib/main.js @@ -35,7 +35,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var ndslice = require( '@stdlib/ndarray-base-slice' ); var Slice = require( '@stdlib/slice-ctor' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,10 +92,10 @@ function nditerSelectDimension( x, dim ) { 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 ( !isInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + throw new TypeError( format( 'null7f', dim ) ); } opts = { 'writable': false, @@ -104,20 +104,20 @@ function nditerSelectDimension( x, dim ) { 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' ) ); } } if ( hasOwnProp( options, 'keepdim' ) ) { if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) ); + throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); } opts.keepdim = options.keepdim; } @@ -129,7 +129,7 @@ function nditerSelectDimension( x, dim ) { // Normalize the dimension index: d = normalizeIndex( dim, ndims-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) ); + throw new RangeError( format( 'nullF8', ndims, dim ) ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index ec80183..1b98bb3 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 5fd6df279e0b3db4abca8cd70d7b3ed520b81773 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 03:26:25 +0000 Subject: [PATCH 19/26] Remove files --- index.d.ts | 92 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4939 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 d5d7768..0000000 --- a/index.d.ts +++ /dev/null @@ -1,92 +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; - - /** - * Boolean indicating whether returned views should include the selected dimension as a singleton dimension (default: false). - * - * ## Notes - * - * - Including the selected dimension as a singleton dimension can be useful when wanting to ensure that returned views remain broadcast compatible with the input ndarray. - */ - keepdim?: boolean; -} - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param x - input value -* @param dim - dimension index -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @param options.keepdim - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x: typedndarray, dim: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSelectDimension; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c0d14ce..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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6897601..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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1e359cd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a7aaf3484b13a541951c97c238bbab6592cec93f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Dec 2024 03:27:04 +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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - 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 | 224 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1093 ---- 43 files changed, 4878 insertions(+), 5226 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 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 342315d..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/select-dimension) 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 7a01fd4..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/select-dimension) 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 6963002..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 12 * * 2' - - # 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 + + ```
@@ -254,7 +245,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]. @@ -319,19 +310,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/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 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 d8e7344..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 nditerSelectDimension = 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 = nditerSelectDimension( x, 0 ); - 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 = nditerSelectDimension( x, 0 ); - - 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 9c014b1..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/select-dimension" -%% click B href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/select-dimension -[production-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/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 9c9336c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSelectDimension from '../docs/types/index'; -export = nditerSelectDimension; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c8c28a6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var O=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var c=O(function(B,b){"use strict";var f=require("@stdlib/utils-define-nonenumerable-read-only-property"),S=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-is-boolean").isPrimitive,T=require("@stdlib/assert-is-integer").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),V=require("@stdlib/ndarray-base-assert-is-read-only"),g=require("@stdlib/assert-has-own-property"),y=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-nulls"),R=require("@stdlib/ndarray-shape"),j=require("@stdlib/ndarray-base-normalize-index"),D=require("@stdlib/ndarray-base-numel"),F=require("@stdlib/ndarray-base-slice"),I=require("@stdlib/slice-ctor"),L=require("@stdlib/slice-base-args2multislice"),a=require("@stdlib/string-format");function q(i,r){var e,s,l,n,o,p,d,v,u,t;if(!P(i))throw new TypeError(a("invalid argument. First argument must be an ndarray. Value: `%s`.",i));if(!T(r))throw new TypeError(a("invalid argument. Second argument must be an integer. Value: `%s`.",r));if(n={writable:!1,keepdim:!1},arguments.length>2){if(e=arguments[2],!S(e))throw new TypeError(a("invalid argument. Options argument must be an object. Value: `%s`.",e));if(g(e,"readonly")){if(!w(e.readonly))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",e.readonly));if(n.writable=!e.readonly,n.writable&&V(i))throw new Error(a("invalid option. Cannot write to read-only array."))}if(g(e,"keepdim")){if(!w(e.keepdim))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","keepdim",e.keepdim));n.keepdim=e.keepdim}}if(s=R(i),l=s.length,u=j(r,l-1),u===-1)throw new RangeError(a("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",l,r));return v=D(s),v===0&&(p=!0),v=s[u],t=-1,d=x(l),o={},f(o,"next",h),f(o,"return",k),y&&f(o,y,E),o;function h(){var m;return t+=1,p||t>=v?{done:!0}:(n.keepdim?d[u]=new I(t,t+1,1):d[u]=t,m=L(d),{value:F(i,m,!0,n.writable),done:!1})}function k(m){return p=!0,arguments.length?{value:m,done:!0}:{done:!0}}function E(){return q(i,r,n)}}b.exports=q});var N=c();module.exports=N; -/** -* @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. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2254776..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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndslice = require( '@stdlib/ndarray-base-slice' );\nvar Slice = require( '@stdlib/slice-ctor' );\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\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 ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSelectDimension;\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 view along a specified dimension.\n*\n* @module @stdlib/ndarray-iter-select-dimension\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSelectDimension( x, 0 );\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,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAU,QAAS,4BAA6B,EAChDC,EAAQ,QAAS,oBAAqB,EACtCC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA4C9C,SAASC,EAAuBC,EAAGC,EAAM,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACd,EAAWe,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAI,CAAE,EAM1G,GAJAI,EAAO,CACN,SAAY,GACZ,QAAW,EACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKb,EAAYa,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYjB,EAAYY,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACA,GAAKT,EAAYa,EAAS,SAAU,EAAI,CACvC,GAAK,CAACjB,EAAWiB,EAAQ,OAAQ,EAChC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAQ,OAAQ,CAAE,EAE3HG,EAAK,QAAUH,EAAQ,OACxB,CACD,CAOA,GALAC,EAAQX,EAAUQ,CAAE,EACpBI,EAAQD,EAAM,OAGdO,EAAIjB,EAAgBQ,EAAKG,EAAM,CAAE,EAC5BM,IAAM,GACV,MAAM,IAAI,WAAYZ,EAAQ,6GAA8GM,EAAOH,CAAI,CAAE,EAG1J,OAAAQ,EAAIf,EAAOS,CAAM,EACZM,IAAM,IACVF,EAAM,IAGPE,EAAIN,EAAOO,CAAE,EAGbC,EAAI,GAGJH,EAAMjB,EAAOa,CAAM,EAGnBE,EAAO,CAAC,EACRvB,EAAauB,EAAM,OAAQM,CAAK,EAChC7B,EAAauB,EAAM,SAAUO,CAAI,EAG5BvB,GACJP,EAAauB,EAAMhB,EAAgBwB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CACf,IAAIG,EAGJ,OADAJ,GAAK,EACAJ,GAAOI,GAAKF,EACT,CACN,KAAQ,EACT,GAGIJ,EAAK,QACTG,EAAKE,CAAE,EAAI,IAAId,EAAOe,EAAGA,EAAE,EAAG,CAAE,EAEhCH,EAAKE,CAAE,EAAIC,EAGZI,EAAIlB,EAAiBW,CAAI,EAGlB,CACN,MAASb,EAASK,EAAGe,EAAG,GAAMV,EAAK,QAAS,EAC5C,KAAQ,EACT,EACD,CASA,SAASQ,EAAKG,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOf,EAAuBC,EAAGC,EAAKI,CAAK,CAC5C,CACD,CAKAvB,EAAO,QAAUiB,IC3KjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "nulls", "getShape", "normalizeIndex", "numel", "ndslice", "Slice", "args2multislice", "format", "nditerSelectDimension", "x", "dim", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "N", "d", "i", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 33d2556..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, dim[, options] ) - Returns an iterator which iterates over each view along a specified - dimension. - - 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. - - dim: integer - Dimension index. If less than zero, the index is resolved relative to - the last dimension, with the last dimension corresponding to the value - `-1`. - - 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. - - options.keepdim: boolean (optional) - Boolean indicating whether returned views should include the selected - dimension as a singleton dimension. Including the selected dimension as - a singleton dimension can be useful when wanting to ensure that returned - views remain broadcast compatible with the input ndarray. Default: - false. - - 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, 0 ); - > 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 ecb7b9d..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 nditerSelectDimension = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); // $ExpectType Iterator> - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSelectDimension( 123, 0 ); // $ExpectError - nditerSelectDimension( true, 0 ); // $ExpectError - nditerSelectDimension( false, 0 ); // $ExpectError - nditerSelectDimension( null, 0 ); // $ExpectError - nditerSelectDimension( undefined, 0 ); // $ExpectError - nditerSelectDimension( {}, 0 ); // $ExpectError - nditerSelectDimension( [], 0 ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0 ); // $ExpectError - - nditerSelectDimension( 123, 0, {} ); // $ExpectError - nditerSelectDimension( true, 0, {} ); // $ExpectError - nditerSelectDimension( false, 0, {} ); // $ExpectError - nditerSelectDimension( null, 0, {} ); // $ExpectError - nditerSelectDimension( undefined, 0, {} ); // $ExpectError - nditerSelectDimension( {}, 0, {} ); // $ExpectError - nditerSelectDimension( [], 0, {} ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSelectDimension( 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... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 'abc' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 123 ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 'abc' } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 123 } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': null } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': [] } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': {} } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSelectDimension(); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 872011c..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 nditerSelectDimension = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSelectDimension( x, 0 ); - -// 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 5acbfd8..d5d7768 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..c0d14ce --- /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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6897601 --- /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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 766d309..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 view along a specified dimension. -* -* @module @stdlib/ndarray-iter-select-dimension -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSelectDimension( x, 0 ); -* -* 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 f298502..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndslice = require( '@stdlib/ndarray-base-slice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param {ndarray} x - input value -* @param {integer} dim - dimension index -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} second argument must be an integer -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x, dim ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var N; - var d; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isInteger( dim ) ) { - throw new TypeError( format( 'null7f', dim ) ); - } - opts = { - 'writable': false, - 'keepdim': 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' ) ); - } - } - if ( hasOwnProp( options, 'keepdim' ) ) { - if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); - } - opts.keepdim = options.keepdim; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Normalize the dimension index: - d = normalizeIndex( dim, ndims-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'nullF8', ndims, dim ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of views (i.e., the dimension size): - N = shape[ d ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = nulls( ndims ); - - // 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; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Update the index array to generate the next view: - if ( opts.keepdim ) { - idx[ d ] = new Slice( i, i+1, 1 ); - } else { - idx[ d ] = i; - } - // Create a multi-slice for the next view: - s = args2multislice( idx ); - - // Return the next slice: - return { - 'value': ndslice( 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 nditerSelectDimension( x, dim, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSelectDimension; diff --git a/package.json b/package.json index 1b98bb3..a15ba47 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each view along a specified dimension.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-normalize-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/slice-ctor": "^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..1e359cd --- /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 58efa84..0000000 --- a/test/test.js +++ /dev/null @@ -1,1093 +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 Slice = require( '@stdlib/slice-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSelectDimension = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSelectDimension, '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() { - nditerSelectDimension( value, 0 ); - }; - } -}); - -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() { - nditerSelectDimension( value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds (options)', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `keepdim` 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'keepdim': 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 - }); - nditerSelectDimension( x, 0, { - 'readonly': false - }); - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=default)', 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 = nditerSelectDimension( x, 0 ); - 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=3, dim=0, keepdim=false)', 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 = nditerSelectDimension( x, 0, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=true)', 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, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 0, { - 'keepdim': true - }); - 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=3, dim=1, keepdim=default)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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=3, dim=1, keepdim=false)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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=3, dim=2, keepdim=default)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( 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=3, dim=2, keepdim=false)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=2, keepdim=true)', 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, null, null, new Slice( 0, 1 ) ), - 'done': false - }, - { - 'value': slice( x, null, null, new Slice( 1, 2 ) ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': true - }); - 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, dim=1, keepdim=default)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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, dim=1, keepdim=false)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), 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, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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, dim=1)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - '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 = nditerSelectDimension( x, 0 ); - 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' ); - } - - it = nditerSelectDimension( x, 1 ); - 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' ); - } - - it = nditerSelectDimension( 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 nditerSelectDimension; - var it1; - var it2; - var x; - var i; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSelectDimension( x, 0 ); - 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 nditerSelectDimension; - var it; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From fd9156f9ddd61e09cf4c1cdcb953dfd5a981c637 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Dec 2024 01:56:09 +0000 Subject: [PATCH 21/26] Transform error messages --- lib/main.js | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 04145c7..f298502 100644 --- a/lib/main.js +++ b/lib/main.js @@ -35,7 +35,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var ndslice = require( '@stdlib/ndarray-base-slice' ); var Slice = require( '@stdlib/slice-ctor' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,10 +92,10 @@ function nditerSelectDimension( x, dim ) { 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 ( !isInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + throw new TypeError( format( 'null7f', dim ) ); } opts = { 'writable': false, @@ -104,20 +104,20 @@ function nditerSelectDimension( x, dim ) { 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' ) ); } } if ( hasOwnProp( options, 'keepdim' ) ) { if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) ); + throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); } opts.keepdim = options.keepdim; } @@ -129,7 +129,7 @@ function nditerSelectDimension( x, dim ) { // Normalize the dimension index: d = normalizeIndex( dim, ndims-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) ); + throw new RangeError( format( 'nullF8', ndims, dim ) ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index ec80183..1b98bb3 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 10133ef88a7558e436460c07f653ba002c9b2859 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Dec 2024 02:11:27 +0000 Subject: [PATCH 22/26] Remove files --- index.d.ts | 92 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4939 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 d5d7768..0000000 --- a/index.d.ts +++ /dev/null @@ -1,92 +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; - - /** - * Boolean indicating whether returned views should include the selected dimension as a singleton dimension (default: false). - * - * ## Notes - * - * - Including the selected dimension as a singleton dimension can be useful when wanting to ensure that returned views remain broadcast compatible with the input ndarray. - */ - keepdim?: boolean; -} - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param x - input value -* @param dim - dimension index -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @param options.keepdim - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x: typedndarray, dim: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSelectDimension; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c0d14ce..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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6897601..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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1e359cd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c405008dae96cee3661b88c22078317a29c41403 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Dec 2024 02:12:03 +0000 Subject: [PATCH 23/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 | 50 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 65 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - 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 | 224 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1093 ---- 44 files changed, 4878 insertions(+), 5227 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 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/.keepalive b/.github/.keepalive deleted file mode 100644 index f4da75d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-23T01:50:55.955Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 342315d..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/select-dimension) 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 7a01fd4..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/select-dimension) 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 6963002..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 12 * * 2' - - # 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 + + ```
@@ -254,7 +245,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]. @@ -319,19 +310,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/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 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 d8e7344..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 nditerSelectDimension = 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 = nditerSelectDimension( x, 0 ); - 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 = nditerSelectDimension( x, 0 ); - - 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 9c014b1..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/select-dimension" -%% click B href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/select-dimension -[production-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/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 9c9336c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSelectDimension from '../docs/types/index'; -export = nditerSelectDimension; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c8c28a6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var O=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var c=O(function(B,b){"use strict";var f=require("@stdlib/utils-define-nonenumerable-read-only-property"),S=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-is-boolean").isPrimitive,T=require("@stdlib/assert-is-integer").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),V=require("@stdlib/ndarray-base-assert-is-read-only"),g=require("@stdlib/assert-has-own-property"),y=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-nulls"),R=require("@stdlib/ndarray-shape"),j=require("@stdlib/ndarray-base-normalize-index"),D=require("@stdlib/ndarray-base-numel"),F=require("@stdlib/ndarray-base-slice"),I=require("@stdlib/slice-ctor"),L=require("@stdlib/slice-base-args2multislice"),a=require("@stdlib/string-format");function q(i,r){var e,s,l,n,o,p,d,v,u,t;if(!P(i))throw new TypeError(a("invalid argument. First argument must be an ndarray. Value: `%s`.",i));if(!T(r))throw new TypeError(a("invalid argument. Second argument must be an integer. Value: `%s`.",r));if(n={writable:!1,keepdim:!1},arguments.length>2){if(e=arguments[2],!S(e))throw new TypeError(a("invalid argument. Options argument must be an object. Value: `%s`.",e));if(g(e,"readonly")){if(!w(e.readonly))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",e.readonly));if(n.writable=!e.readonly,n.writable&&V(i))throw new Error(a("invalid option. Cannot write to read-only array."))}if(g(e,"keepdim")){if(!w(e.keepdim))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","keepdim",e.keepdim));n.keepdim=e.keepdim}}if(s=R(i),l=s.length,u=j(r,l-1),u===-1)throw new RangeError(a("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",l,r));return v=D(s),v===0&&(p=!0),v=s[u],t=-1,d=x(l),o={},f(o,"next",h),f(o,"return",k),y&&f(o,y,E),o;function h(){var m;return t+=1,p||t>=v?{done:!0}:(n.keepdim?d[u]=new I(t,t+1,1):d[u]=t,m=L(d),{value:F(i,m,!0,n.writable),done:!1})}function k(m){return p=!0,arguments.length?{value:m,done:!0}:{done:!0}}function E(){return q(i,r,n)}}b.exports=q});var N=c();module.exports=N; -/** -* @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. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2254776..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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndslice = require( '@stdlib/ndarray-base-slice' );\nvar Slice = require( '@stdlib/slice-ctor' );\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\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 ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSelectDimension;\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 view along a specified dimension.\n*\n* @module @stdlib/ndarray-iter-select-dimension\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSelectDimension( x, 0 );\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,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAU,QAAS,4BAA6B,EAChDC,EAAQ,QAAS,oBAAqB,EACtCC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA4C9C,SAASC,EAAuBC,EAAGC,EAAM,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACd,EAAWe,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAI,CAAE,EAM1G,GAJAI,EAAO,CACN,SAAY,GACZ,QAAW,EACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKb,EAAYa,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYjB,EAAYY,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACA,GAAKT,EAAYa,EAAS,SAAU,EAAI,CACvC,GAAK,CAACjB,EAAWiB,EAAQ,OAAQ,EAChC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAQ,OAAQ,CAAE,EAE3HG,EAAK,QAAUH,EAAQ,OACxB,CACD,CAOA,GALAC,EAAQX,EAAUQ,CAAE,EACpBI,EAAQD,EAAM,OAGdO,EAAIjB,EAAgBQ,EAAKG,EAAM,CAAE,EAC5BM,IAAM,GACV,MAAM,IAAI,WAAYZ,EAAQ,6GAA8GM,EAAOH,CAAI,CAAE,EAG1J,OAAAQ,EAAIf,EAAOS,CAAM,EACZM,IAAM,IACVF,EAAM,IAGPE,EAAIN,EAAOO,CAAE,EAGbC,EAAI,GAGJH,EAAMjB,EAAOa,CAAM,EAGnBE,EAAO,CAAC,EACRvB,EAAauB,EAAM,OAAQM,CAAK,EAChC7B,EAAauB,EAAM,SAAUO,CAAI,EAG5BvB,GACJP,EAAauB,EAAMhB,EAAgBwB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CACf,IAAIG,EAGJ,OADAJ,GAAK,EACAJ,GAAOI,GAAKF,EACT,CACN,KAAQ,EACT,GAGIJ,EAAK,QACTG,EAAKE,CAAE,EAAI,IAAId,EAAOe,EAAGA,EAAE,EAAG,CAAE,EAEhCH,EAAKE,CAAE,EAAIC,EAGZI,EAAIlB,EAAiBW,CAAI,EAGlB,CACN,MAASb,EAASK,EAAGe,EAAG,GAAMV,EAAK,QAAS,EAC5C,KAAQ,EACT,EACD,CASA,SAASQ,EAAKG,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOf,EAAuBC,EAAGC,EAAKI,CAAK,CAC5C,CACD,CAKAvB,EAAO,QAAUiB,IC3KjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "nulls", "getShape", "normalizeIndex", "numel", "ndslice", "Slice", "args2multislice", "format", "nditerSelectDimension", "x", "dim", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "N", "d", "i", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 33d2556..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, dim[, options] ) - Returns an iterator which iterates over each view along a specified - dimension. - - 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. - - dim: integer - Dimension index. If less than zero, the index is resolved relative to - the last dimension, with the last dimension corresponding to the value - `-1`. - - 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. - - options.keepdim: boolean (optional) - Boolean indicating whether returned views should include the selected - dimension as a singleton dimension. Including the selected dimension as - a singleton dimension can be useful when wanting to ensure that returned - views remain broadcast compatible with the input ndarray. Default: - false. - - 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, 0 ); - > 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 ecb7b9d..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 nditerSelectDimension = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); // $ExpectType Iterator> - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSelectDimension( 123, 0 ); // $ExpectError - nditerSelectDimension( true, 0 ); // $ExpectError - nditerSelectDimension( false, 0 ); // $ExpectError - nditerSelectDimension( null, 0 ); // $ExpectError - nditerSelectDimension( undefined, 0 ); // $ExpectError - nditerSelectDimension( {}, 0 ); // $ExpectError - nditerSelectDimension( [], 0 ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0 ); // $ExpectError - - nditerSelectDimension( 123, 0, {} ); // $ExpectError - nditerSelectDimension( true, 0, {} ); // $ExpectError - nditerSelectDimension( false, 0, {} ); // $ExpectError - nditerSelectDimension( null, 0, {} ); // $ExpectError - nditerSelectDimension( undefined, 0, {} ); // $ExpectError - nditerSelectDimension( {}, 0, {} ); // $ExpectError - nditerSelectDimension( [], 0, {} ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSelectDimension( 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... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 'abc' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 123 ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 'abc' } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 123 } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': null } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': [] } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': {} } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSelectDimension(); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 872011c..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 nditerSelectDimension = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSelectDimension( x, 0 ); - -// 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 5acbfd8..d5d7768 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..c0d14ce --- /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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6897601 --- /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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 766d309..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 view along a specified dimension. -* -* @module @stdlib/ndarray-iter-select-dimension -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSelectDimension( x, 0 ); -* -* 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 f298502..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndslice = require( '@stdlib/ndarray-base-slice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param {ndarray} x - input value -* @param {integer} dim - dimension index -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} second argument must be an integer -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x, dim ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var N; - var d; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isInteger( dim ) ) { - throw new TypeError( format( 'null7f', dim ) ); - } - opts = { - 'writable': false, - 'keepdim': 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' ) ); - } - } - if ( hasOwnProp( options, 'keepdim' ) ) { - if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); - } - opts.keepdim = options.keepdim; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Normalize the dimension index: - d = normalizeIndex( dim, ndims-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'nullF8', ndims, dim ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of views (i.e., the dimension size): - N = shape[ d ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = nulls( ndims ); - - // 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; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Update the index array to generate the next view: - if ( opts.keepdim ) { - idx[ d ] = new Slice( i, i+1, 1 ); - } else { - idx[ d ] = i; - } - // Create a multi-slice for the next view: - s = args2multislice( idx ); - - // Return the next slice: - return { - 'value': ndslice( 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 nditerSelectDimension( x, dim, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSelectDimension; diff --git a/package.json b/package.json index 1b98bb3..a15ba47 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each view along a specified dimension.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-normalize-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/slice-ctor": "^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..1e359cd --- /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 58efa84..0000000 --- a/test/test.js +++ /dev/null @@ -1,1093 +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 Slice = require( '@stdlib/slice-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSelectDimension = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSelectDimension, '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() { - nditerSelectDimension( value, 0 ); - }; - } -}); - -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() { - nditerSelectDimension( value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds (options)', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `keepdim` 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'keepdim': 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 - }); - nditerSelectDimension( x, 0, { - 'readonly': false - }); - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=default)', 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 = nditerSelectDimension( x, 0 ); - 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=3, dim=0, keepdim=false)', 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 = nditerSelectDimension( x, 0, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=true)', 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, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 0, { - 'keepdim': true - }); - 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=3, dim=1, keepdim=default)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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=3, dim=1, keepdim=false)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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=3, dim=2, keepdim=default)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( 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=3, dim=2, keepdim=false)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=2, keepdim=true)', 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, null, null, new Slice( 0, 1 ) ), - 'done': false - }, - { - 'value': slice( x, null, null, new Slice( 1, 2 ) ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': true - }); - 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, dim=1, keepdim=default)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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, dim=1, keepdim=false)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), 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, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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, dim=1)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - '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 = nditerSelectDimension( x, 0 ); - 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' ); - } - - it = nditerSelectDimension( x, 1 ); - 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' ); - } - - it = nditerSelectDimension( 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 nditerSelectDimension; - var it1; - var it2; - var x; - var i; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSelectDimension( x, 0 ); - 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 nditerSelectDimension; - var it; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 69e15d0b03b08d717a2898535145e3efe149fbcb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 01:42:43 +0000 Subject: [PATCH 24/26] Transform error messages --- lib/main.js | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index 04145c7..f298502 100644 --- a/lib/main.js +++ b/lib/main.js @@ -35,7 +35,7 @@ var numel = require( '@stdlib/ndarray-base-numel' ); var ndslice = require( '@stdlib/ndarray-base-slice' ); var Slice = require( '@stdlib/slice-ctor' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -92,10 +92,10 @@ function nditerSelectDimension( x, dim ) { 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 ( !isInteger( dim ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) ); + throw new TypeError( format( 'null7f', dim ) ); } opts = { 'writable': false, @@ -104,20 +104,20 @@ function nditerSelectDimension( x, dim ) { 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' ) ); } } if ( hasOwnProp( options, 'keepdim' ) ) { if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) ); + throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); } opts.keepdim = options.keepdim; } @@ -129,7 +129,7 @@ function nditerSelectDimension( x, dim ) { // Normalize the dimension index: d = normalizeIndex( dim, ndims-1 ); if ( d === -1 ) { - throw new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) ); + throw new RangeError( format( 'nullF8', ndims, dim ) ); } // Check whether the input array is empty... N = numel( shape ); diff --git a/package.json b/package.json index ec80183..1b98bb3 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/slice-base-args2multislice": "^0.2.2", "@stdlib/slice-ctor": "^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 bf39d75b8b697307b8c2a86d73194e0aa98a51f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 02:29:23 +0000 Subject: [PATCH 25/26] Remove files --- index.d.ts | 92 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4939 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 d5d7768..0000000 --- a/index.d.ts +++ /dev/null @@ -1,92 +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; - - /** - * Boolean indicating whether returned views should include the selected dimension as a singleton dimension (default: false). - * - * ## Notes - * - * - Including the selected dimension as a singleton dimension can be useful when wanting to ensure that returned views remain broadcast compatible with the input ndarray. - */ - keepdim?: boolean; -} - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param x - input value -* @param dim - dimension index -* @param options - function options -* @param options.readonly - boolean indicating whether returned views should be read-only -* @param options.keepdim - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x: typedndarray, dim: number, options?: Options ): Iterator>; - - -// EXPORTS // - -export = nditerSelectDimension; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c0d14ce..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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6897601..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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1e359cd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3a75d6b7c0197b787730e74f2ec620f3e1222344 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 02:29:56 +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 | 65 +- SECURITY.md | 5 - benchmark/benchmark.js | 85 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - 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 | 224 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1093 ---- 44 files changed, 4878 insertions(+), 5230 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 16f0109..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-30T01:25:05.869Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8657b35..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/select-dimension) 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 7a01fd4..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/select-dimension) 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 6963002..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 12 * * 2' - - # 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 + + ```
@@ -254,7 +245,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]. @@ -319,19 +310,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/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/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 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 d8e7344..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 nditerSelectDimension = 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 = nditerSelectDimension( x, 0 ); - 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 = nditerSelectDimension( x, 0 ); - - 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 9c014b1..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/select-dimension" -%% click B href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/select-dimension -[production-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-select-dimension/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-select-dimension/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 9c9336c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerSelectDimension from '../docs/types/index'; -export = nditerSelectDimension; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c8c28a6..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var O=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var c=O(function(B,b){"use strict";var f=require("@stdlib/utils-define-nonenumerable-read-only-property"),S=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-is-boolean").isPrimitive,T=require("@stdlib/assert-is-integer").isPrimitive,P=require("@stdlib/assert-is-ndarray-like"),V=require("@stdlib/ndarray-base-assert-is-read-only"),g=require("@stdlib/assert-has-own-property"),y=require("@stdlib/symbol-iterator"),x=require("@stdlib/array-base-nulls"),R=require("@stdlib/ndarray-shape"),j=require("@stdlib/ndarray-base-normalize-index"),D=require("@stdlib/ndarray-base-numel"),F=require("@stdlib/ndarray-base-slice"),I=require("@stdlib/slice-ctor"),L=require("@stdlib/slice-base-args2multislice"),a=require("@stdlib/string-format");function q(i,r){var e,s,l,n,o,p,d,v,u,t;if(!P(i))throw new TypeError(a("invalid argument. First argument must be an ndarray. Value: `%s`.",i));if(!T(r))throw new TypeError(a("invalid argument. Second argument must be an integer. Value: `%s`.",r));if(n={writable:!1,keepdim:!1},arguments.length>2){if(e=arguments[2],!S(e))throw new TypeError(a("invalid argument. Options argument must be an object. Value: `%s`.",e));if(g(e,"readonly")){if(!w(e.readonly))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","readonly",e.readonly));if(n.writable=!e.readonly,n.writable&&V(i))throw new Error(a("invalid option. Cannot write to read-only array."))}if(g(e,"keepdim")){if(!w(e.keepdim))throw new TypeError(a("invalid option. `%s` option must be a boolean. Option: `%s`.","keepdim",e.keepdim));n.keepdim=e.keepdim}}if(s=R(i),l=s.length,u=j(r,l-1),u===-1)throw new RangeError(a("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",l,r));return v=D(s),v===0&&(p=!0),v=s[u],t=-1,d=x(l),o={},f(o,"next",h),f(o,"return",k),y&&f(o,y,E),o;function h(){var m;return t+=1,p||t>=v?{done:!0}:(n.keepdim?d[u]=new I(t,t+1,1):d[u]=t,m=L(d),{value:F(i,m,!0,n.writable),done:!1})}function k(m){return p=!0,arguments.length?{value:m,done:!0}:{done:!0}}function E(){return q(i,r,n)}}b.exports=q});var N=c();module.exports=N; -/** -* @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. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 2254776..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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar ndslice = require( '@stdlib/ndarray-base-slice' );\nvar Slice = require( '@stdlib/slice-ctor' );\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* var 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\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 ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerSelectDimension;\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 view along a specified dimension.\n*\n* @module @stdlib/ndarray-iter-select-dimension\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerSelectDimension( x, 0 );\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,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,0CAA2C,EACjEC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAiB,QAAS,sCAAuC,EACjEC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAU,QAAS,4BAA6B,EAChDC,EAAQ,QAAS,oBAAqB,EACtCC,EAAkB,QAAS,oCAAqC,EAChEC,EAAS,QAAS,uBAAwB,EA4C9C,SAASC,EAAuBC,EAAGC,EAAM,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACxB,EAAea,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAK,CAACd,EAAWe,CAAI,EACpB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAI,CAAE,EAM1G,GAJAI,EAAO,CACN,SAAY,GACZ,QAAW,EACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAH,EAAU,UAAW,CAAE,EAClB,CAAClB,EAAekB,CAAQ,EAC5B,MAAM,IAAI,UAAWJ,EAAQ,qEAAsEI,CAAQ,CAAE,EAE9G,GAAKb,EAAYa,EAAS,UAAW,EAAI,CACxC,GAAK,CAACjB,EAAWiB,EAAQ,QAAS,EACjC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,WAAYI,EAAQ,QAAS,CAAE,EAG7H,GADAG,EAAK,SAAW,CAACH,EAAQ,SACpBG,EAAK,UAAYjB,EAAYY,CAAE,EACnC,MAAM,IAAI,MAAOF,EAAQ,kDAAmD,CAAE,CAEhF,CACA,GAAKT,EAAYa,EAAS,SAAU,EAAI,CACvC,GAAK,CAACjB,EAAWiB,EAAQ,OAAQ,EAChC,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,UAAWI,EAAQ,OAAQ,CAAE,EAE3HG,EAAK,QAAUH,EAAQ,OACxB,CACD,CAOA,GALAC,EAAQX,EAAUQ,CAAE,EACpBI,EAAQD,EAAM,OAGdO,EAAIjB,EAAgBQ,EAAKG,EAAM,CAAE,EAC5BM,IAAM,GACV,MAAM,IAAI,WAAYZ,EAAQ,6GAA8GM,EAAOH,CAAI,CAAE,EAG1J,OAAAQ,EAAIf,EAAOS,CAAM,EACZM,IAAM,IACVF,EAAM,IAGPE,EAAIN,EAAOO,CAAE,EAGbC,EAAI,GAGJH,EAAMjB,EAAOa,CAAM,EAGnBE,EAAO,CAAC,EACRvB,EAAauB,EAAM,OAAQM,CAAK,EAChC7B,EAAauB,EAAM,SAAUO,CAAI,EAG5BvB,GACJP,EAAauB,EAAMhB,EAAgBwB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CACf,IAAIG,EAGJ,OADAJ,GAAK,EACAJ,GAAOI,GAAKF,EACT,CACN,KAAQ,EACT,GAGIJ,EAAK,QACTG,EAAKE,CAAE,EAAI,IAAId,EAAOe,EAAGA,EAAE,EAAG,CAAE,EAEhCH,EAAKE,CAAE,EAAIC,EAGZI,EAAIlB,EAAiBW,CAAI,EAGlB,CACN,MAASb,EAASK,EAAGe,EAAG,GAAMV,EAAK,QAAS,EAC5C,KAAQ,EACT,EACD,CASA,SAASQ,EAAKG,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASF,GAAU,CAClB,OAAOf,EAAuBC,EAAGC,EAAKI,CAAK,CAC5C,CACD,CAKAvB,EAAO,QAAUiB,IC3KjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isBoolean", "isInteger", "isndarrayLike", "isReadOnly", "hasOwnProp", "iteratorSymbol", "nulls", "getShape", "normalizeIndex", "numel", "ndslice", "Slice", "args2multislice", "format", "nditerSelectDimension", "x", "dim", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "N", "d", "i", "next", "end", "factory", "s", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 33d2556..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, dim[, options] ) - Returns an iterator which iterates over each view along a specified - dimension. - - 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. - - dim: integer - Dimension index. If less than zero, the index is resolved relative to - the last dimension, with the last dimension corresponding to the value - `-1`. - - 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. - - options.keepdim: boolean (optional) - Boolean indicating whether returned views should include the selected - dimension as a singleton dimension. Including the selected dimension as - a singleton dimension can be useful when wanting to ensure that returned - views remain broadcast compatible with the input ndarray. Default: - false. - - 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, 0 ); - > 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 ecb7b9d..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 nditerSelectDimension = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); // $ExpectType Iterator> - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {} ); // $ExpectType Iterator> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerSelectDimension( 123, 0 ); // $ExpectError - nditerSelectDimension( true, 0 ); // $ExpectError - nditerSelectDimension( false, 0 ); // $ExpectError - nditerSelectDimension( null, 0 ); // $ExpectError - nditerSelectDimension( undefined, 0 ); // $ExpectError - nditerSelectDimension( {}, 0 ); // $ExpectError - nditerSelectDimension( [], 0 ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0 ); // $ExpectError - - nditerSelectDimension( 123, 0, {} ); // $ExpectError - nditerSelectDimension( true, 0, {} ); // $ExpectError - nditerSelectDimension( false, 0, {} ); // $ExpectError - nditerSelectDimension( null, 0, {} ); // $ExpectError - nditerSelectDimension( undefined, 0, {} ); // $ExpectError - nditerSelectDimension( {}, 0, {} ); // $ExpectError - nditerSelectDimension( [], 0, {} ); // $ExpectError - nditerSelectDimension( ( x: number ): number => x, 0, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), ( x: number ): number => x ); // $ExpectError - - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), '123', {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), true, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), false, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), null, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), undefined, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), {}, {} ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), [], {} ); // $ExpectError - nditerSelectDimension( 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... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 'abc' ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 123 ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, true ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, false ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, null ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, [] ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 'abc' } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': 123 } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': null } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': [] } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': {} } ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - nditerSelectDimension(); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ) ); // $ExpectError - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 872011c..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 nditerSelectDimension = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for iterating over matrices: -var it = nditerSelectDimension( x, 0 ); - -// 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 5acbfd8..d5d7768 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..373a1e9 --- /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-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-read-only@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import m 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-nulls@esm/index.mjs";import o 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-normalize-index@v0.2.2-esm/index.mjs";import p 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 h from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-ctor@v0.2.2-esm/index.mjs";import f 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 b(c,u){var g,y,w,x,k,E,T,F,z,P;if(!i(c))throw new TypeError(v("null4f",c));if(!t(u))throw new TypeError(v("null7f",u));if(x={writable:!1,keepdim:!1},arguments.length>2){if(!r(g=arguments[2]))throw new TypeError(v("null2V",g));if(d(g,"readonly")){if(!s(g.readonly))throw new TypeError(v("null2o","readonly",g.readonly));if(x.writable=!g.readonly,x.writable&&n(c))throw new Error(v("nullF4"))}if(d(g,"keepdim")){if(!s(g.keepdim))throw new TypeError(v("null2o","keepdim",g.keepdim));x.keepdim=g.keepdim}}if(w=(y=o(c)).length,-1===(z=a(u,w-1)))throw new RangeError(v("nullF8",w,u));return 0===(F=p(y))&&(E=!0),F=y[z],P=-1,T=l(w),e(k={},"next",(function(){var e;if(P+=1,E||P>=F)return{done:!0};x.keepdim?T[z]=new h(P,P+1,1):T[z]=P;return e=f(T),{value:j(c,e,!0,x.writable),done:!1}})),e(k,"return",(function(e){if(E=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),m&&e(k,m,(function(){return b(c,u,x)})),k}export{b as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6897601 --- /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 isInteger } from '@stdlib/assert-is-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 nulls from '@stdlib/array-base-nulls';\nimport getShape from '@stdlib/ndarray-shape';\nimport normalizeIndex from '@stdlib/ndarray-base-normalize-index';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndslice from '@stdlib/ndarray-base-slice';\nimport Slice from '@stdlib/slice-ctor';\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 view along a specified dimension.\n*\n* @param {ndarray} x - input value\n* @param {integer} dim - dimension index\n* @param {Options} [options] - function options\n* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only\n* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} second argument must be an integer\n* @throws {RangeError} dimension index exceeds the number of dimensions\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} cannot write to a read-only array\n* @returns {Iterator} iterator\n*\n* @example\n* import 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 = nditerSelectDimension( x, 0 );\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 nditerSelectDimension( x, dim ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar N;\n\tvar d;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f', x ) );\n\t}\n\tif ( !isInteger( dim ) ) {\n\t\tthrow new TypeError( format( 'null7f', dim ) );\n\t}\n\topts = {\n\t\t'writable': false,\n\t\t'keepdim': 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\tif ( hasOwnProp( options, 'keepdim' ) ) {\n\t\t\tif ( !isBoolean( options.keepdim ) ) {\n\t\t\t\tthrow new TypeError( format( 'null2o', 'keepdim', options.keepdim ) );\n\t\t\t}\n\t\t\topts.keepdim = options.keepdim;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Normalize the dimension index:\n\td = normalizeIndex( dim, ndims-1 );\n\tif ( d === -1 ) {\n\t\tthrow new RangeError( format( 'nullF8', ndims, dim ) );\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 views (i.e., the dimension size):\n\tN = shape[ d ];\n\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array for generating slices:\n\tidx = nulls( ndims );\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\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// Update the index array to generate the next view:\n\t\tif ( opts.keepdim ) {\n\t\t\tidx[ d ] = new Slice( i, i+1, 1 );\n\t\t} else {\n\t\t\tidx[ d ] = i;\n\t\t}\n\t\t// Create a multi-slice for the next view:\n\t\ts = args2multislice( idx );\n\n\t\t// Return the next slice:\n\t\treturn {\n\t\t\t'value': ndslice( 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 nditerSelectDimension( x, dim, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerSelectDimension;\n"],"names":["nditerSelectDimension","x","dim","options","shape","ndims","opts","iter","FLG","idx","N","d","i","isndarrayLike","TypeError","format","isInteger","writable","keepdim","arguments","length","isPlainObject","hasOwnProp","isBoolean","readonly","isReadOnly","Error","getShape","normalizeIndex","RangeError","numel","nulls","setReadOnly","s","done","Slice","args2multislice","value","ndslice","iteratorSymbol"],"mappings":";;+hDAiFA,SAASA,EAAuBC,EAAGC,GAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,SAAUd,IAExC,IAAMe,EAAWd,GAChB,MAAM,IAAIY,UAAWC,EAAQ,SAAUb,IAMxC,GAJAI,EAAO,CACNW,UAAY,EACZC,SAAW,GAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNlB,EAAUgB,UAAW,IAEpB,MAAM,IAAIL,UAAWC,EAAQ,SAAUZ,IAExC,GAAKmB,EAAYnB,EAAS,YAAe,CACxC,IAAMoB,EAAWpB,EAAQqB,UACxB,MAAM,IAAIV,UAAWC,EAAQ,SAAU,WAAYZ,EAAQqB,WAG5D,GADAlB,EAAKW,UAAYd,EAAQqB,SACpBlB,EAAKW,UAAYQ,EAAYxB,GACjC,MAAM,IAAIyB,MAAOX,EAAQ,UAE1B,CACD,GAAKO,EAAYnB,EAAS,WAAc,CACvC,IAAMoB,EAAWpB,EAAQe,SACxB,MAAM,IAAIJ,UAAWC,EAAQ,SAAU,UAAWZ,EAAQe,UAE3DZ,EAAKY,QAAUf,EAAQe,OACvB,CACD,CAOD,GAJAb,GADAD,EAAQuB,EAAU1B,IACJmB,QAIF,KADZT,EAAIiB,EAAgB1B,EAAKG,EAAM,IAE9B,MAAM,IAAIwB,WAAYd,EAAQ,SAAUV,EAAOH,IAyBhD,OArBW,KADXQ,EAAIoB,EAAO1B,MAEVI,GAAM,GAGPE,EAAIN,EAAOO,GAGXC,GAAK,EAGLH,EAAMsB,EAAO1B,GAIb2B,EADAzB,EAAO,CAAA,EACY,QAenB,WACC,IAAI0B,EAGJ,GADArB,GAAK,EACAJ,GAAOI,GAAKF,EAChB,MAAO,CACNwB,MAAQ,GAIL5B,EAAKY,QACTT,EAAKE,GAAM,IAAIwB,EAAOvB,EAAGA,EAAE,EAAG,GAE9BH,EAAKE,GAAMC,EAMZ,OAHAqB,EAAIG,EAAiB3B,GAGd,CACN4B,MAASC,EAASrC,EAAGgC,GAAG,EAAM3B,EAAKW,UACnCiB,MAAQ,EAET,IArCDF,EAAazB,EAAM,UA8CnB,SAAc8B,GAEb,GADA7B,GAAM,EACDW,UAAUC,OACd,MAAO,CACNiB,MAASA,EACTH,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IAtDIK,GACJP,EAAazB,EAAMgC,GA6DpB,WACC,OAAOvC,EAAuBC,EAAGC,EAAKI,EACtC,IA7DMC,CA8DR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 766d309..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 view along a specified dimension. -* -* @module @stdlib/ndarray-iter-select-dimension -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var nditerSelectDimension = require( '@stdlib/ndarray-iter-select-dimension' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerSelectDimension( x, 0 ); -* -* 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 f298502..0000000 --- a/lib/main.js +++ /dev/null @@ -1,224 +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 isInteger = require( '@stdlib/assert-is-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 nulls = require( '@stdlib/array-base-nulls' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var normalizeIndex = require( '@stdlib/ndarray-base-normalize-index' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndslice = require( '@stdlib/ndarray-base-slice' ); -var Slice = require( '@stdlib/slice-ctor' ); -var args2multislice = require( '@stdlib/slice-base-args2multislice' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each view along a specified dimension. -* -* @param {ndarray} x - input value -* @param {integer} dim - dimension index -* @param {Options} [options] - function options -* @param {boolean} [options.readonly=true] - boolean indicating whether returned views should be read-only -* @param {boolean} [options.keepdim=false] - boolean indicating whether returned views should include the selected dimension as a singleton dimension -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} second argument must be an integer -* @throws {RangeError} dimension index exceeds the number of dimensions -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} cannot write to a read-only array -* @returns {Iterator} iterator -* -* @example -* var 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 = nditerSelectDimension( x, 0 ); -* -* 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 nditerSelectDimension( x, dim ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var N; - var d; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f', x ) ); - } - if ( !isInteger( dim ) ) { - throw new TypeError( format( 'null7f', dim ) ); - } - opts = { - 'writable': false, - 'keepdim': 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' ) ); - } - } - if ( hasOwnProp( options, 'keepdim' ) ) { - if ( !isBoolean( options.keepdim ) ) { - throw new TypeError( format( 'null2o', 'keepdim', options.keepdim ) ); - } - opts.keepdim = options.keepdim; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Normalize the dimension index: - d = normalizeIndex( dim, ndims-1 ); - if ( d === -1 ) { - throw new RangeError( format( 'nullF8', ndims, dim ) ); - } - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Compute the number of views (i.e., the dimension size): - N = shape[ d ]; - - // Initialize a counter: - i = -1; - - // Initialize an index array for generating slices: - idx = nulls( ndims ); - - // 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; - - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - // Update the index array to generate the next view: - if ( opts.keepdim ) { - idx[ d ] = new Slice( i, i+1, 1 ); - } else { - idx[ d ] = i; - } - // Create a multi-slice for the next view: - s = args2multislice( idx ); - - // Return the next slice: - return { - 'value': ndslice( 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 nditerSelectDimension( x, dim, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerSelectDimension; diff --git a/package.json b/package.json index 1b98bb3..a15ba47 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which iterates over each view along a specified dimension.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-nulls": "github:stdlib-js/array-base-nulls#main", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-normalize-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/slice-ctor": "^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..1e359cd --- /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 58efa84..0000000 --- a/test/test.js +++ /dev/null @@ -1,1093 +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 Slice = require( '@stdlib/slice-ctor' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var nditerSelectDimension = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerSelectDimension, '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() { - nditerSelectDimension( value, 0 ); - }; - } -}); - -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() { - nditerSelectDimension( value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an integer (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), value ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is out-of-bounds (options)', function test( t ) { - var values; - var i; - - values = [ - 10, - 11, - 12, - -10, - -11, - -12 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerSelectDimension( 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'readonly': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `keepdim` 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() { - nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0, { - 'keepdim': 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 - }); - nditerSelectDimension( x, 0, { - 'readonly': false - }); - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=default)', 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 = nditerSelectDimension( x, 0 ); - 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=3, dim=0, keepdim=false)', 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 = nditerSelectDimension( x, 0, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=0, keepdim=true)', 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, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 0, { - 'keepdim': true - }); - 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=3, dim=1, keepdim=default)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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=3, dim=1, keepdim=false)', 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, null, 0, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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=3, dim=2, keepdim=default)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( 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=3, dim=2, keepdim=false)', 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, null, null, 0 ), - 'done': false - }, - { - 'value': slice( x, null, null, 1 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': 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 ), true, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, dim=2, keepdim=true)', 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, null, null, new Slice( 0, 1 ) ), - 'done': false - }, - { - 'value': slice( x, null, null, new Slice( 1, 2 ) ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 2, { - 'keepdim': true - }); - 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, dim=1, keepdim=default)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1 ); - 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, dim=1, keepdim=false)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': 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 ), 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, dim=1, keepdim=true)', 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, null, new Slice( 0, 1 ), null, null ), - 'done': false - }, - { - 'value': slice( x, null, new Slice( 1, 2 ), null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - 'keepdim': true - }); - 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, dim=1)', 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, null, 0, null, null ), - 'done': false - }, - { - 'value': slice( x, null, 1, null, null ), - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerSelectDimension( x, 1, { - '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 = nditerSelectDimension( x, 0 ); - 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' ); - } - - it = nditerSelectDimension( x, 1 ); - 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' ); - } - - it = nditerSelectDimension( 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - - 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 nditerSelectDimension; - var it1; - var it2; - var x; - var i; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ] ] ); - - it1 = nditerSelectDimension( x, 0 ); - 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 nditerSelectDimension; - var it; - - nditerSelectDimension = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerSelectDimension( zeros( [ 2, 2, 2 ] ), 0 ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -});